# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41098 | Hassoony | Kas (COCI17_kas) | C++14 | 1167 ms | 399356 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef double D;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=(1<<30);
const int SQ=1e6+9;
const int MX=509;
int n,a[MX],dp[MX][100000*2+9],sum;
int DP(int x,int y){
if(x==n){
if(y==100000)return 0;
return -inf;
}
int &ret=dp[x][y];if(ret!=-1)return ret;
ret=DP(x+1,y);
ret=max(ret,DP(x+1,y+a[x])+a[x]);
ret=max(ret,DP(x+1,y-a[x]));
return ret;
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
memset(dp,-1,sizeof(dp));
cout<<sum-DP(0,100000)<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |