Submission #89581


Source Code Expand

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int q,m,k,t,T[2005],S[2005],res;
bool DP[150005];
void read()
{
	int i;
	scanf("%d %d %d",&q,&m,&k);
	for(i=1;i<=m;i++)
	{
		scanf("%d",&T[i]);
		t+=T[i];
	}
	for(i=1;i<=k;i++)
		scanf("%d",&S[i]);
	sort(S+1,S+k+1,greater < int > ());
}
void knapsack()
{
	int i,j;
	DP[0]=1;
	for(i=1;i<=m;i++)
		for(j=q-T[i];j>=0;j--)
			if(DP[j])
				DP[j+T[i]]=1;
}
void solve()
{
	int i,s=0,d;
	for(i=q;i>=0;i--)
		if(DP[i])
			break;
	if(i==q) { res=q; return; }
	if(i<t) { res=q-1; return; }
	d=q-i;
	for(i=1;i<=k;i++)
	{
		if(d>0)
		{
			s++;
			d-=S[i];
		}
		else
			break;
	}
	res=q-s;
}
int main()
{
	read();
	knapsack();
	solve();
	printf("%d\n",res);
	return 0;
}

Submission Info

Submission Time
Task 14 - Farmer
User Eren
Language C++ (G++ 4.6.4)
Score 100
Code Size 795 Byte
Status AC
Exec Time 473 ms
Memory 900 KB

Compile Error

./Main.cpp: In function ‘void read()’:
./Main.cpp:10:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:13:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:17:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Judge Result

Set Name Set01 Set02 Set03 Set04 Set05 Set06 Set07 Set08 Set09 Set10 Set11 Set12 Set13 Set14 Set15 Set16 Set17 Set18 Set19 Set20
Score / Max Score 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
Set01 01
Set02 02
Set03 03
Set04 04
Set05 05
Set06 06
Set07 07
Set08 08
Set09 09
Set10 10
Set11 11
Set12 12
Set13 13
Set14 14
Set15 15
Set16 16
Set17 17
Set18 18
Set19 19
Set20 20
Case Name Status Exec Time Memory
01 AC 22 ms 784 KB
02 AC 21 ms 760 KB
03 AC 23 ms 772 KB
04 AC 23 ms 784 KB
05 AC 27 ms 784 KB
06 AC 23 ms 768 KB
07 AC 23 ms 784 KB
08 AC 20 ms 780 KB
09 AC 25 ms 788 KB
10 AC 22 ms 792 KB
11 AC 161 ms 792 KB
12 AC 201 ms 816 KB
13 AC 196 ms 880 KB
14 AC 204 ms 880 KB
15 AC 225 ms 780 KB
16 AC 299 ms 892 KB
17 AC 325 ms 900 KB
18 AC 425 ms 868 KB
19 AC 466 ms 824 KB
20 AC 473 ms 892 KB