Doing Homework again
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
homework to do. Every teacher gives him a deadline of handing in the
homework. If Ignatius hands in the homework after the deadline, the teacher will
reduce his score of the final test. And now we assume that doing everyone
homework always takes one day. Beacuse Bobo is very lazy.So he wants you to
help him to arrange the order of doing homework to minimize the reduced score.
Input
Each test case start with a positive integer N(1<=N<=500) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
Output
Sample Input
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
Sample Output
0 35
#include<iostream> #include <algorithm> using namespace std; struct node { int dead; int scord; }; bool cmp(node a,node b) { return a.scord>b.scord; } int main() { int t; cin>>t; node lessons[10005]; int flag[10005]; while(t--) { int n,ans=0; cin>>n; fill(flag,flag+1005,0); for(int i=0;i<n;i++) cin>>lessons[i].dead; for(int i=0;i<n;i++) cin>>lessons[i].scord; sort(lessons,lessons+n,cmp); for(int i=0;i<n;i++) { int te=lessons[i].dead; while(flag[te]){ te--;} if(te<=0) ans+=lessons[i].scord; else flag[te]=1; } cout<<ans<<endl; } return 0; }