Submission #2229773


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n)  RFOR(i,0,n)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
#define P pair<int,int>
#define PPi pair<P,int>
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int N,W;
	ll a,b,c,d,result=-INF;
	vector<vector<ll>> v(4);

	cin>>N>>W;
	cin>>a>>b; v[0].pb(b);
	REP(i,N-1){
		cin>>c>>d;
		v[c-a].pb(d);
	}
	
	REP(i,4){
		DVSORT(v[i]);
		FOR(j,1,v[i].size()) v[i][j]+=v[i][j-1]; //累積和を取ることで計算量を減らす
		v[i].insert(v[i].begin(),0);
	}
	

	REP(i,v[0].size()){
		REP(j,v[1].size()){
			REP(r,v[2].size()){
				REP(k,v[3].size()){
					ll weight=a*i+(a+1)*j+(a+2)*r+(a+3)*k;
					if(W<weight) break;
					else chmax(result,v[0][i]+v[1][j]+v[2][r]+v[3][k]);
				}
			}
		}
	}
	print(result);
	return 0;
}


Submission Info

Submission Time
Task D - Simple Knapsack
User stnae678
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1688 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 16
Set Name Test Cases
Sample example0, example1, example2, example3
All antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2
Case Name Status Exec Time Memory
antigreedy0 AC 1 ms 256 KB
antigreedy1 AC 1 ms 256 KB
antigreedy2 AC 1 ms 256 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
example3 AC 1 ms 256 KB
quarter0 AC 1 ms 256 KB
quarter1 AC 1 ms 256 KB
quarter2 AC 1 ms 256 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB
smallw0 AC 1 ms 256 KB
smallw1 AC 1 ms 256 KB
smallw2 AC 1 ms 256 KB