Submission #1531689


Source Code Expand

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=110;
typedef long long ll;
//ll a[maxn];
ll w[maxn];
ll v[4][maxn];
ll sum[4][maxn];
int cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int n,w;
	while(~scanf("%d%d",&n,&w))
	{
		int a[4]={1,1,1,1};
		ll temp=0;
		for(int i=1;i<=n;++i)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			if(i == 1)
				temp = x;
			v[x-temp][a[x-temp]++]=y;
		}
		sort(v[0]+1,v[0]+a[0]+1,cmp);
		sort(v[1]+1,v[1]+a[1]+1,cmp);
		sort(v[2]+1,v[2]+a[2]+1,cmp);
		sort(v[3]+1,v[3]+a[3]+1,cmp);
		for(int i=0;i<4;++i)
		{
			for(int j=1;j<a[i];++j)
			{
				sum[i][j]=sum[i][j-1]+v[i][j];
			}
		}
		ll ans = 0;
		for(int i=0;i<a[0];++i)
		{
			for(int j=0;j<a[1];++j)
			{
				for(int k=0;k<a[2];++k)
				{
					for(int l=0;l<a[3];++l)
					{
						if(temp*i+(temp+1)*j+(temp+2)*k+(temp+3)*l<=w)
						{
							ans=max(ans,sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l]);
						}
					}
				}
			}
		}
		printf("%lld\n",ans);
	}
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:25:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d",&x,&y);
                       ^

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