Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- using System.Text;
- namespace solution
- {
- class Pair : IComparable<Pair>
- {
- public Pair(int index, long price, int count)
- {
- Price = price;
- Index = index;
- }
- public int Index;
- public long Price;
- public int Count;
- public override bool Equals(object obj)
- {
- if (obj is Pair)
- {
- Pair p = (Pair)obj;
- return p.Index == Index;
- }
- return base.Equals(obj);
- }
- public override int GetHashCode()
- {
- return Index.GetHashCode();
- }
- public int CompareTo(Pair p)
- {
- int r = Price.CompareTo(p.Price);
- if (r == 0)
- {
- return Index.CompareTo(p.Index);
- }
- return r;
- }
- }
- static class Program
- {
- static void InitIO(string name)
- {
- #if !DEBUG
- Console.SetIn(new StreamReader(name + ".in"));
- Console.SetOut(new StreamWriter(name + ".out"));
- #endif
- }
- static void Main(string[] args)
- {
- InitIO("cakes");
- args = Console.ReadLine().Split(' ');
- var n = int.Parse(args[0]);
- var t = long.Parse(args[1]);
- List<long> dprice = new List<long>();
- List<long> prices = new List<long>();
- for (var i = 0; i < n; i++)
- {
- args = Console.ReadLine().Split(' ');
- var xi = int.Parse(args[0]);
- var ti = long.Parse(args[1]);
- prices.Add(ti);
- dprice.Add(xi);
- }
- int max = 0;
- List<long> l = new List<long>();
- for (var i = 0; i < n; i++)
- {
- l.Add(prices[i]);
- long nt = t - dprice[i];
- for(var j = l.Count - 1; j >= 1; j--)
- {
- if (l[j] >= l[j - 1]) break;
- else
- {
- var c = l[j];
- l[j] = l[j - 1];
- l[j - 1] = c;
- }
- }
- int v = 0;
- for (var j = 0; j < l.Count; j++)
- {
- if(l[j] <= nt)
- {
- nt -= l[j];
- v++;
- }
- }
- max = Math.Max(v, max);
- }
- Console.WriteLine(max);
- Console.Out.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement