Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 3 KB
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Jegyek
{
class Limit : IComparable<Limit>
{
public int limit, distance;
public Limit( int _limit, int _distance )
{
limit = _limit;
distance = _distance;
}
#region IComparable<Limit> Members
public int CompareTo(Limit other)
{
return -distance.CompareTo(other.distance);
}
#endregion
}
class Program
{
private int n, m;
private List<int> points;
public Program()
{
StreamReader ins = new StreamReader("jegyek.be");
string[] line = ins.ReadLine().Split(' ');
n = int.Parse(line[0]);
m = int.Parse(line[1]);
points = new List<int>(n);
for (int i = 0; i < n; i++)
{
points.Add(int.Parse(ins.ReadLine()));
}
points.Sort();
List<Limit> limits = getAllPossibleLimits( points );
List<int> goodLimits = new List<int>(4);
if (limits.Count >= 4) {
limits.Sort();
goodLimits = new List<int>(4);
for (int i = 0; i < 4; i++)
{
goodLimits.Add( limits[i].limit );
}
goodLimits.Sort();
}
printOut( goodLimits );
}
private void printOut( List<int> limits )
{
StreamWriter outs = new StreamWriter("jegyek.ki");
if (limits.Count != 4)
{
outs.WriteLine(0);
}
else
{
limits.ForEach(delegate(int limit) { outs.WriteLine(limit); });
outs.WriteLine(m);
}
outs.Close();
}
private List<Limit> getAllPossibleLimits( List<int> points )
{
List<Limit> limits = new List<Limit>(m-1);
for (int i = 1; i < points.Count; i++)
{
if (points[i] - 1 > points[i - 1])
{
limits.Add( new Limit( points[i]-1, points[i]-1 - points[i-1] ) );
}
}
return limits;
}
static void Main(string[] args)
{
new Program();
}
}
}