java 100% ac题解
圈地运动
http://www.nowcoder.com/questionTerminal/37554f9e45404fa785bd029e5f08280e
import java.util.Scanner; public class Main{ public static void main (String[]args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); if(n<3){ System.out.println(-1); } int first=in.nextInt(),second=in.nextInt(); int sum=first+second; int max=Math.max(first, second); for(int i=2;i<n;i++){ int temp=in.nextInt(); max=Math.max(temp,max); sum=sum+temp-max; if(max<sum){ System.out.println(i+1); break; } else{ sum+=max; } if(i==n-1){ System.out.println(-1); } } } }