Submission #332290

#TimeUsernameProblemLanguageResultExecution timeMemory
332290alien_loverHacker (BOI15_hac)C++14
0 / 100
1 ms364 KiB
#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'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...