This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// carot15
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) begin(x), end(x)
#define mp make_pair
#define cyd {cout<<"Yes";return;}
#define cyn {cout<<"No";return;}
const ll nmax=5e6+5;
const ll mod=1e9+7;
const int X[]={0,0,1,-1};
const int Y[]={-1,1,0,0};
bitset<nmax> bit;
int n,a[505],t=0;
void solve(){
cin>>n;
bit[0]=1;
for (int i=1;i<=n;i++){
cin>>a[i];
t+=a[i];
bit|=bit<<a[i];
}
ll ans=t;
for (int i=1;i<=t/2;i++){
if (bit[i]){
ll p=t-i*2;
if (bit[p])
ans=p;
}
}
cout<<ans+(t-ans)/2;
}
/*
z
t-z
*/
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// freopen(".INP", "r", stdin);
// freopen(".OUT", "w", stdout);
int T=1;
// cin>>T;
while(T--){
solve();
cout<<'\n';
}
}
# | 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... |