# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
839220 |
2023-08-29T08:37:10 Z |
teo_thrash |
Kas (COCI17_kas) |
C++14 |
|
130 ms |
3436 KB |
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn=1e5+10;
const int mod=1e9+7;
int n;
ll a[503];
ll dp[maxn], sum=0; ///dp[i] is the max sum of the subsequences that when split optimally, the 2 parts differ by i
ll otgore[maxn], otdolu[maxn], smqna[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(int i=0; i<n; i++){
cin>>a[i];
sum+=a[i];
}
sort(a, a+n, greater<int>() );
dp[a[0]]=a[0];
otgore[a[0]]=otdolu[a[0]]=smqna[a[0]]=a[0];
for(int i=1; i<n; i++){
dp[a[i]]=max(dp[a[i]], a[i]);
for(int j=0; j<=sum-a[i]; j++){
if(dp[j+a[i]]!=0){
otgore[j]=dp[j+a[i]]+a[i];
}
}
for(int j=a[i]; j<=sum; j++){
if(dp[j-a[i]]!=0){
otdolu[j]=dp[j-a[i]]+a[i];
}
}
for(int j=1; j<a[i]; j++){
if(dp[j]!=0){
smqna[a[i]-j]=dp[j]+a[i];
}
}
for(int j=0; j<=sum; j++){
dp[j]=max(dp[j], max(otgore[j], max(otdolu[j], smqna[j])));
otgore[j]=otdolu[j]=smqna[j]=-1;
}
}
cout<<sum - dp[0]/2<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
3436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
130 ms |
3432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |