/*********************ALLAH HO AKBAR***********************/
/************HAZRAT MUHAMMAD (Peace be upon him)***********/
#include <bits/stdc++.h>
using namespace std;
#define int long long
int const N=1e6+5;
int pre[N];
int arr[N];
int n;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n;
int sm=0;
for (int i = 1; i <=n; ++i){
cin>>arr[i];
sm+=arr[i];
}
for (int i = 1; i <=n; ++i)
arr[i+n]=arr[i];
int k=(n/2)+(n%2);
for (int i = 1; i <=2*n; ++i)
pre[i]=pre[i-1]+arr[i];
vector<pair<int,int>> v;
for (int i = 1; i <=n; ++i)
{
int chunk=pre[(i+k)-1]-pre[i-1];
int chunk2=sm-chunk;
if(chunk>=chunk2)
v.push_back({chunk-chunk2,chunk});
}
sort(v.begin(), v.end());
cout<<v[0].second<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |