#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
const int PRIME = 1e9 + 7;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("TASK_NAME.in", "r", stdin);
// freopen("TASK_NAME.out", "w", stdout);
// Use scanf printf
int n;
cin >> n;
vector<int> scores(n);
int maxNumHacked = (n + 1) / 2;
int totSum = 0;
for(int i = 0; i < n; i++){
cin >> scores[i];
totSum += scores[i];
}
int windowScore = 0;
for(int i = 0; i < maxNumHacked; i++){
windowScore += scores[i];
}
int minDiff = windowScore * 2 - totSum;
int bestScore = windowScore;
for(int i = 0; i < n; i++){
// compare window starting at i
// subtract element at i, add next element
if(abs(windowScore * 2 - totSum) < minDiff && windowScore > totSum - windowScore){
minDiff = windowScore * 2 - totSum;
bestScore = windowScore;
}
// maxScore = min(minDiff, windowScore);
windowScore -= scores[i];
windowScore += scores[(i + maxNumHacked) % n];
}
cout << bestScore << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |