标签:
import java.io.BufferedInputStream; import java.math.BigInteger; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; class Node{ int x,y; int f; Node(){}; } class Mycmp implements Comparator{ public int compare(Object arg0, Object arg1){ Node t1=(Node)arg0; Node t2=(Node)arg1; if(t1.x==t2.x) return t1.f>t2.f?1:-1; return t1.x>t2.x?1:-1; } } public class Main { public static void main(String[] args) { Node[] d=new Node[200010]; for(int i=0;i<200010;++i) d[i] = new Node(); Scanner cin = new Scanner(new BufferedInputStream(System.in)); int T; T = cin.nextInt(); int n,m; while(T!=0){ T--; n = cin.nextInt(); m = cin.nextInt(); int i; for(i=0;i<n;++i){ d[i].x = cin.nextInt(); d[i].y = cin.nextInt(); d[i].f = 1; } for(;i<m+n;++i){ d[i].x = cin.nextInt(); d[i].y = cin.nextInt(); d[i].f = 2; } Arrays.sort(d, 0, m+n, new Mycmp()); BigInteger ans = BigInteger.valueOf(0); BigInteger numy = BigInteger.valueOf(0); for(i=0;i<n+m;++i){ if(d[i].f==2) numy = numy.add(BigInteger.valueOf(d[i].y)); else ans = ans.add(numy.multiply(BigInteger.valueOf(d[i].y))); } System.out.println(ans); } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/mengxingyuanlove/article/details/48105319