Description
Input
Output
Sample Input
Sample Output
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <map> 5 #include <algorithm> 6 using namespace std; 7 typedef struct abcd 8 { 9 int w,l; 10 }abcd; 11 abcd a[1200]; 12 bool cmp(abcd x,abcd y) 13 { 14 if(x.w==y.w)return x.l>y.l; 15 return x.w>y.w; 16 } 17 map<int,int> m; 18 int main() 19 { 20 int t,n,i,j,ans; 21 scanf("%d",&t); 22 while(t--) 23 { 24 scanf("%d",&n); 25 for(i=0;i<n;i++) 26 scanf("%d",&a[i].l); 27 for(i=0;i<n;i++) 28 scanf("%d",&a[i].w); 29 sort(a,a+n,cmp); 30 m.clear(); 31 ans=0; 32 for(i=0;i<n;i++) 33 { 34 if(m[a[i].l]==0) 35 { 36 m[a[i].l]=1; 37 } 38 else 39 { 40 while(a[i].l>0&&m[a[i].l])a[i].l--; 41 if(a[i].l>0)m[a[i].l]=1; 42 else ans+=a[i].w; 43 } 44 } 45 cout<<ans<<endl; 46 } 47 }
Doing Homework again,布布扣,bubuko.com
原文:http://www.cnblogs.com/ERKE/p/3842038.html