이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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){
minDiff = windowScore * 2 - totSum;
bestScore = windowScore;
}
// maxScore = min(minDiff, windowScore);
windowScore -= scores[i];
windowScore += scores[(i + maxNumHacked) % n];
}
cout << bestScore << '\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... |