This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
int n; cin >> n;
deque<int> nums;
for (int i = 0; i < n; i++){
int g; cin >> g;
nums.push_back(g);
}
int ans = 0;
while (nums.size() > 1){
if (nums.front() == nums.back()){
nums.pop_front();
nums.pop_back();
} else if (nums.back() < nums.front()){
int to_add = nums[nums.size() - 1] + nums[nums.size() - 2];
nums.pop_back();
nums.pop_back();
nums.push_back(to_add);
ans++;
} else {
int to_add = nums[0] + nums[1];
nums.pop_front();
nums.pop_front();
nums.push_front(to_add);
ans++;
}
}
cout << ans << '\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... |