Skip to content

Instantly share code, notes, and snippets.

@PedroRacchetti
Created September 6, 2021 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PedroRacchetti/90eb533ea2f6cc83a43aae7f6c5297ef to your computer and use it in GitHub Desktop.
Save PedroRacchetti/90eb533ea2f6cc83a43aae7f6c5297ef to your computer and use it in GitHub Desktop.
#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