算法
代码
package tanxin;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
class ws implements Comparable<ws>{
int was;
int w;
public ws(int was, int w) {
super();
this.was = was;
this.w = w;
}
@Override
public int compareTo(ws q) {
// TODO Auto-generated method stub
return this.was-q.was;
}
}
public class 耍杂技的牛 {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(bufferedReader.readLine());
ws b[]=new ws[n];
for(int i=0;i<n;i++){
String p[]=bufferedReader.readLine().split(" ");
int w=Integer.parseInt(p[0]);
int s=Integer.parseInt(p[1]);
b[i]=new ws(w+s, w);
}
Arrays.sort(b);
int res=(int) -1e9;
for(int i=0,sum=0;i<n;i++){
int w=b[i].w;
int s=b[i].was-w;
res=Math.max(res, sum-s);
sum+=w;
}
System.out.println(res);
}
}
清秀hh
字好看
字真好看