Created
September 6, 2021 13:06
-
-
Save PedroRacchetti/90eb533ea2f6cc83a43aae7f6c5297ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
const int MAXN = 1e6 + 10; | |
typedef long long ll; | |
ll l[MAXN]; | |
int n; | |
int main(){ | |
scanf("%d", &n); | |
for(int i = 1; i <= n; i++){ | |
scanf("%lld", &l[i]); | |
} | |
//Iniciamos os iteradores e a resposta | |
int it1 = 1, it2 = n; | |
int ans = 0; | |
while(it1 < it2){ | |
if(l[it1] == l[it2]){ | |
it1++; | |
it2--; | |
continue; | |
} | |
//Sempre que precisamos fazer uma operação, | |
//incrementamos a resposta | |
if(l[it1] > l[it2] ){ | |
l[it2-1] += l[it2]; | |
it2--; | |
ans++; | |
} | |
else{ | |
l[it1+1] += l[it1]; | |
it1++; | |
ans++; | |
} | |
} | |
//Imprmimos a resposta | |
printf("%d\n", ans); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment