#include #include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N; ll W; pair P[5050]; ll ma=0; bool cmp(pair L,pair R) { return L.first*R.second>N>>W; FOR(i,N) cin>>P[i].second>>P[i].first; /* sort(P,P+N,cmp); reverse(P,P+N); dfs(0,0,0); */ srand(time(NULL)); gettimeofday(&start,NULL); while(1) { gettimeofday(&end,NULL); ll span = (end.tv_sec - start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec); if(span>1500000) break; FOR(i,10) { random_shuffle(P,P+N); ll w=0,v=0; FOR(j,N) { if(w+P[j].first<=W) { w+=P[j].first; v+=P[j].second; } } ma=max(ma,v); } } cout<