Submission #158001


Source Code Expand

#include <bits/stdc++.h>
 
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define lli long long int
#define foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define FP( ii,aa,bb ) for( int ii=aa;ii<=bb;ii++ )
#define FM( ii,aa,bb ) for( int ii=aa;ii>=bb;ii-- )
 
using namespace std;
 
int q,n,m,arr[50000],s[155],dp[150005];
 
int main(){
	int tree=0;
	cin >> q >> n >> m;
	FP( i,1,n ){
		cin >> arr[i];
		tree += arr[i];
	}
	int maxi=0;
	dp[0] = 1;
	FP( i,1,n ){
		FM( j,q,arr[i] )
			if( dp[j-arr[i]] ){
				dp[j] = 1;
				maxi = max( maxi,j );
			}
	}
	if( maxi==q ){
		cout << maxi << endl;
		return 0;
	}
	if( tree>=q ){
		cout << maxi+(q-maxi-1) << endl;
		return 0;
	}
	q -= maxi;
	int res=maxi;
	FP( i,1,m )
		cin >> arr[i];
	sort( arr+1,arr+m+1 );
	FM( i,m,1 ){
		if( arr[i]<=q ){
			q -= arr[i];
			res += arr[i]-1;
			continue;
		}
		res += q-1;
		break;
	}
	cout << res << endl;
}

Submission Info

Submission Time
Task 14 - Farmer
User enesoncu
Language C++ (G++ 4.6.4)
Score 100
Code Size 1011 Byte
Status AC
Exec Time 599 ms
Memory 2436 KB

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 121 ms 1800 KB
02 AC 40 ms 1928 KB
03 AC 37 ms 1788 KB
04 AC 39 ms 1800 KB
05 AC 37 ms 1936 KB
06 AC 44 ms 1792 KB
07 AC 39 ms 1800 KB
08 AC 38 ms 1928 KB
09 AC 38 ms 1936 KB
10 AC 39 ms 1812 KB
11 AC 215 ms 2060 KB
12 AC 236 ms 2064 KB
13 AC 245 ms 2056 KB
14 AC 257 ms 2064 KB
15 AC 283 ms 2056 KB
16 AC 377 ms 2200 KB
17 AC 408 ms 2176 KB
18 AC 463 ms 2176 KB
19 AC 546 ms 2312 KB
20 AC 599 ms 2436 KB