Skip to content

Instantly share code, notes, and snippets.

@luccasiau
Created March 29, 2015 03:25
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 luccasiau/c8d988d87bdefad085c9 to your computer and use it in GitHub Desktop.
Save luccasiau/c8d988d87bdefad085c9 to your computer and use it in GitHub Desktop.
import java.io.*;
public class solucao{
public static void main(String[] args)throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int[] vet = new int[110000];
int i,n,sm1,sm2;
String[] aux;
n = Integer.parseInt(in.readLine());
aux = in.readLine().split(" ");
sm1 = 0;
sm2 = 0;
for(i = 0; i < n; i++){
vet[i] = Integer.parseInt(aux[i]);
sm1 += vet[i];
}
sm1 -= vet[i-1];
sm2 += vet[i-1];
for(i = n - 2; i > -1; i--){
if(sm1 == sm2){
out.write((i+1)+"\n");
break;
}
else {
sm1 -= vet[i];
sm2 += vet[i];
}
}
out.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment