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 fi first
#define se second
using namespace std;
using ll = long long;
const int maxN = 1e6 + 1;
const int MOD = 1e9 + 7;
int n;
deque<ll> DQ;
void ReadInput()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
ll x; cin >> x;
DQ.push_back(x);
}
}
void Solve()
{
ll res = 0;
while (DQ.size() > 1)
{
if (DQ.front() == DQ.back())
{
DQ.pop_back();
DQ.pop_front();
continue;
}
if (!DQ.empty())
{
res++;
int tmp;
if (DQ.front() > DQ.back())
{
tmp = DQ.back();
DQ.pop_back();
DQ.back() += tmp;
}
else
{
tmp = DQ.front();
DQ.pop_front();
DQ.front() += tmp;
}
}
}
cout << res;
}
#define task ""
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
int T = 1;
//cin >> T;
while (T--)
{
ReadInput();
Solve();
}
}
# | 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... |