void main(){ import std.stdio, std.string, std.conv, std.algorithm; import std.typecons; int n; long wmax; rd(n, wmax); alias T=Tuple!(long, "v", long, "w"); auto a=new T[](n); foreach(i; 0..n) rd(a[i].v, a[i].w); sort!((x, y)=>((1.*x.v/x.w)>(1.*y.v/y.w)))(a); long vsum=0, wsum=0; foreach(e; a){ if((wsum+e.w)<=wmax){ vsum+=e.v; wsum+=e.w; } } writeln(vsum); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } } void wr(T...)(T x){ import std.stdio; foreach(e; x) stderr.write(e, " "); stderr.writeln(); }