SHARE
TWEET

Untitled

a guest Oct 22nd, 2018 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module xxx;
  2.  
  3. import std.stdio, std.bigint, std.conv, std.array, std.string, std.algorithm, std.typecons;
  4.  
  5. void main() {
  6.     auto aa = readln().strip().split();
  7.     auto n = to!int(aa[0]);
  8.     auto s = BigInt(aa[1]);
  9.    
  10.     Tuple!(BigInt, string)[] m;
  11.  
  12.     for (int i = 0; i < n; i++) {
  13.         auto a = readln().strip().split();
  14.         auto name = a[0];
  15.         auto num = BigInt(a[1]);
  16.         m ~= tuple(num, name);
  17.     }
  18.    
  19.     m.sort();
  20.    
  21.     string[] r;
  22.    
  23.     foreach_reverse(t; m) {
  24.         if (s >= t[0]) {
  25.             r ~= t[1];
  26.             s -= t[0];
  27.         }
  28.     }
  29.    
  30.     if (s == 0) {
  31.         writeln(r.length);
  32.        
  33.         foreach(name; r) {
  34.             writeln(name);
  35.         }
  36.     } else {
  37.         writeln(0);
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top