#include<bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
long long n,a[1000006];
int main()
{
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
long long l=0,r=n-1,lsum=a[0],rsum=a[n-1],ans=0;
while(l<r)
{
if(lsum<rsum)
{
l++;
lsum+=a[l];
ans++;
}
else if(lsum>rsum)
{
r--;
rsum+=a[r];
ans++;
}
else
{
lsum=a[l+1];
rsum=a[r-1];
l++;
r--;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
888 KB |
Output is correct |
2 |
Correct |
28 ms |
1016 KB |
Output is correct |
3 |
Correct |
29 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
3028 KB |
Output is correct |
2 |
Correct |
115 ms |
3568 KB |
Output is correct |
3 |
Correct |
134 ms |
4252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
202 ms |
6264 KB |
Output is correct |
2 |
Correct |
213 ms |
6648 KB |
Output is correct |
3 |
Correct |
238 ms |
7396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
263 ms |
7928 KB |
Output is correct |
2 |
Correct |
265 ms |
8156 KB |
Output is correct |
3 |
Correct |
266 ms |
8312 KB |
Output is correct |