标签:mat col format ati max form boa 依次 输入格式
Long long ago,a handsome boy whose name is HSP studied in JSU of information science and engineering. He is clever and always thinks of ways to make fun of others. Now,it is your turn.
HSP和他的女朋友ZM来到了商店,商店有n个糖果,标号依次为1,2,3....n,对应的价值为W1,W2,W3...Wn。现在HSP先拿走一个标号为a的糖果,标号小于a的糖果就被ZM收回去了,然后HSP只能在剩下的糖果中选一个标号为b的糖果,请问Wa-Wb的最大值是多少?
多组数据输入,每一组数据第一行输入一个数字 n(2<=n<=100000),接下来n行,每行输入一个wi表示第i个糖果的价值
(0<wi<=100000)
每组数据输出Wa-Wb的最大值
3
3 2 1
6
1 1 1 1 1 1
2
0
JSU 2015ACM工作组
1 import java.util.Scanner; 2 public class Main { 3 public static void main(String[] args) { 4 Scanner sc=new Scanner(System.in); 5 int n; 6 while(sc.hasNext()) { 7 n=sc.nextInt(); 8 int[] a=new int[n]; 9 for(int i=0;i<n;i++) { 10 a[i]=sc.nextInt(); 11 } 12 int max=-200000; 13 for(int i=0;i<n-1;i++) { 14 int min=a[i+1]; 15 for(int j=n-1;j>=i+1;j--) { 16 if(min>a[j])min=a[j]; 17 } 18 if(max<a[i]-min)max=a[i]-min; 19 } 20 System.out.println(max); 21 } 22 23 } 24 }
测试点2(最后一个测试点)内存超限(待完善)
标签:mat col format ati max form boa 依次 输入格式
原文地址:https://www.cnblogs.com/Flyfishy/p/12163991.html