Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5. using System.Text;
  6.  
  7. namespace solution
  8. {
  9.     class Pair : IComparable<Pair>
  10.     {
  11.         public Pair(int index, long price, int count)
  12.         {
  13.             Price = price;
  14.             Index = index;
  15.         }
  16.  
  17.         public int Index;
  18.         public long Price;
  19.         public int Count;
  20.          
  21.         public override bool Equals(object obj)
  22.         {
  23.             if (obj is Pair)
  24.             {
  25.                 Pair p = (Pair)obj;
  26.                 return p.Index == Index;
  27.             }
  28.             return base.Equals(obj);
  29.         }
  30.         public override int GetHashCode()
  31.         {
  32.             return Index.GetHashCode();
  33.         }
  34.         public int CompareTo(Pair p)
  35.         {
  36.             int r = Price.CompareTo(p.Price);
  37.             if (r == 0)
  38.             {
  39.                 return Index.CompareTo(p.Index);
  40.             }
  41.             return r;
  42.         }
  43.     }
  44.     static class Program
  45.     {
  46.         static void InitIO(string name)
  47.         {
  48.             #if !DEBUG
  49.             Console.SetIn(new StreamReader(name + ".in"));
  50.             Console.SetOut(new StreamWriter(name + ".out"));
  51.             #endif
  52.         }
  53.         static void Main(string[] args)
  54.         {
  55.             InitIO("cakes");
  56.  
  57.             args = Console.ReadLine().Split(' ');
  58.  
  59.             var n = int.Parse(args[0]);
  60.             var t = long.Parse(args[1]);
  61.  
  62.             List<long> dprice = new List<long>();
  63.             List<long> prices = new List<long>();
  64.  
  65.             for (var i = 0; i < n; i++)
  66.             {
  67.                 args = Console.ReadLine().Split(' ');
  68.  
  69.                 var xi = int.Parse(args[0]);
  70.                 var ti = long.Parse(args[1]);
  71.  
  72.                 prices.Add(ti);
  73.                 dprice.Add(xi);
  74.             }
  75.  
  76.             int max = 0;
  77.  
  78.             List<long> l = new List<long>();
  79.             for (var i = 0; i < n; i++)
  80.             {
  81.                 l.Add(prices[i]);
  82.                 long nt = t - dprice[i];
  83.                 for(var j = l.Count - 1; j >= 1; j--)
  84.                 {
  85.                     if (l[j] >= l[j - 1]) break;
  86.                     else
  87.                     {
  88.                         var c = l[j];
  89.                         l[j] = l[j - 1];
  90.                         l[j - 1] = c;
  91.                     }
  92.                 }
  93.                 int v = 0;
  94.                 for (var j = 0; j < l.Count; j++)
  95.                 {
  96.                     if(l[j] <= nt)
  97.                     {
  98.                         nt -= l[j];
  99.                         v++;
  100.                     }
  101.                 }
  102.                 max = Math.Max(v, max);
  103.             }
  104.  
  105.             Console.WriteLine(max);
  106.             Console.Out.Close();
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement