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>
using namespace std;
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sp " "
#define endl "\n"
#define N 1000005
#define modulo 1000000007
#define int long long
int arr[N];
int32_t main()
{
fastio();
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin>>arr[i];
int l = 0, r = n + 1, sl = 0, sr = 0, ans = 0;
int steps = 0;
while(l < r)
{
//cout<<l<<sp<<r<<endl;
while(sl != sr && l < r)
{
while(sl < sr && l < r)
{
//cout<<l<<sp<<r<<sp<<sl<<sp<<sr<<endl;
l++;
sl += arr[l];
ans++;
}
while(sr < sl && l < r)
{
//cout<<l<<sp<<r<<sp<<sl<<sp<<sr<<endl;
r--;
sr += arr[r];
ans++;
}
}
l++, r--;
sl = arr[l], sr = arr[r];
}
cout<<ans<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
Compilation message (stderr)
nizin.cpp: In function 'int32_t main()':
nizin.cpp:27:6: warning: unused variable 'steps' [-Wunused-variable]
27 | int steps = 0;
| ^~~~~
# | 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... |