Submission #1607709


Source Code Expand

#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const int MAX_N=10000;
ll ma=0,v,c; int n,u,b,w;
vector<ll> a[4],s[4];
 
int main(){
	cin >> n >> u >> c >> b;
	a[0].push_back(b);
	REP(i,1,n){
		cin >> w >> v;
		a[w-c].push_back(v);
	}
	REP(i,0,4) sort(a[i].begin(),a[i].end(),greater<ll>());
	REP(i,0,4) s[i].push_back(0);
	REP(i,0,4) REP(j,1,a[i].size()+1) s[i].push_back(s[i][j-1]+a[i][j-1]);
	REP(i,0,a[0].size()+1) REP(j,0,a[1].size()+1) REP(k,0,a[2].size()+1) REP(l,0,a[3].size()+1)
		if((c*i)+(c+1)*j+(c+2)*k+(c+3)*l<=u) ma=max(ma, s[0][i]+s[1][j]+s[2][k]+s[3][l]);
	
	cout << ma << endl;
	return 0;
}

Submission Info

Submission Time
Task D - Simple Knapsack
User ecasdqina
Language C++14 (GCC 5.4.1)
Score 400
Code Size 751 Byte
Status AC
Exec Time 2 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 2 ms 256 KB
quarter1 AC 2 ms 256 KB
quarter2 AC 2 ms 256 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB
smallw0 AC 2 ms 256 KB
smallw1 AC 2 ms 256 KB
smallw2 AC 2 ms 256 KB