Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6522 Accepted Submission(s): 3888
Problem Description
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of 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. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
Input
The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow.
Each test case start with a positive integer N(1<=N<=1000) 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.
Each test case start with a positive integer N(1<=N<=1000) 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
For each test case, you should output the smallest total reduced score, one line per test case.
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 3 5
Author
lcy
Source
Recommend
lcy
贪心~~~
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 1005
#define MAXN 2005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
typedef long long ll;
using namespace std;
struct node
{
int time;
int score;
};
node nod[1010];
int n;
int visit[1010];
int cmp(node a,node b)
{
if (a.score!=b.score)
return a.score>b.score; //按照时间从长到短排序,先完成分数大的作业,这样就保证了失分最少
else
return a.time<b.time; //分数相同的情况下按照时间从短到长排序
}
int main()
{
int i,j,T;
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
memset(visit,0,sizeof(visit));
for (i=0;i<n;i++)
scanf("%d",&nod[i].time);
for (i=0;i<n;i++)
scanf("%d",&nod[i].score);
sort(nod,nod+n,cmp);
int ans=0;
for (i=0;i<n;i++)
{
int t=nod[i].time;
while (t) //从该作业最底期限向前找,找到就标记,表示该天做这个作业
{
if(!visit[t])
{
visit[t]=1;
break;
}
t--;
}
if (t==0) //期限内没有任何一天时间空闲,则该作业无法完成
ans+=nod[i].score;
}
printf("%d\n",ans);
}
return 0;
}
/*
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
*/