hdu 4882 ZCC Loves Codefires

2014 Multi-University Training Contest 2--by 镇海中学 解题报告

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
struct In{
	int t;
	int m;
};
In num[100010];
int cmp(In a,In b){
	return a.t*1.0/a.m<b.t*1.0/b.m;
}
int main(){
	int n,i,j;
	long long k,s;
	while(~scanf("%d",&n)){
		memset(num,0,sizeof(num));
		for(i=0;i<n;i++){
			scanf("%d",&num[i].t);
		}
		for(i=0;i<n;i++){
			scanf("%d",&num[i].m);
		}
		sort(num,num+n,cmp);
		for(k=s=i=0;i<n;i++){
			k+=num[i].t;
			s+=k*num[i].m;
		}
		printf("%I64d\n",s);
	}
	return 0;
}


你可能感兴趣的:(hdu 4882 ZCC Loves Codefires)