编程语言:Java
题目链接:http://poj.org/problem?id=3262
题解:没啥注意的,就是保存结果的变量要用long类型
结果:AC
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static Scanner sc = new Scanner(new BufferedInputStream(System.in));
public static void main(String[] args) throws IOException {
int n=sc.nextInt();
cow[]a=new cow[n];
int sum=0;
for(int i=0;i<n;i++){
int t=sc.nextInt();
int d=sc.nextInt();
a[i]=new cow(t,d);
sum+=d;
}
Arrays.sort(a,new Comparator<cow>(){
@Override
public int compare(cow o1, cow o2) {
return o1.t*o2.d-o1.d*o2.t;
}
});
long res=0;
for(int i=0;i<n;i++){
sum-=a[i].d;
res+=sum*2*a[i].t;
}
out.println(res);
out.flush();
}
}
class cow{
int t;
int d;
public cow(int t, int d) {
this.t = t;
this.d = d;
}
}