nefu218
Time Limit:1000ms
Memory Limit:65536K
Description
小明玩了将近整个寒假,马上就要开学了,现在他有很多寒假作业要做。每一位老师给了他一个交作业的期限。如果在截止日期后交作业,老师就会减少他的期末考试成绩。而现在我们假设每科作业总是做一天。小明让你来帮他安排做作业的计划减少的得分达到最小。
Input
输入包含多组测试用例。输入的第一行是一个整数T,测试用例的数目。T测试用例跟随。每个测试用例开始以一个正整数N(1 < = N < = 1000),表明了寒假作业的数量。.第一行含有N整数代表每个作业应交的期限,下一行中含有N个整数表明被老师降低的分数。
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 3 5
这道题是一道比较简单的贪心,首先考虑分数损失的大小,我先把损失大的分数挽救回来,如果分数相等,就按截止日期从大到小排序,然后竟可能的把分数大的放进数组里。
# include <iostream>
# include <cstring>
# include <algorithm>
using namespace std;
const int maxn = 1005;
struct node
{
int day;
int score;
}s[maxn];
bool cmp(struct node a, struct node b)
{
if(a.score == b.score)
{
return a.day > b.day;
}
return a.score> b.score;
}
int main(int argc, char *argv[])
{
int t;
while(cin >> t)
{
while(t--)
{
memset(s, false, sizeof(s));
int n;
cin >> n;
int maxx= 0;
for(int i = 0; i < n; i++)
{
cin >> s[i].day;
maxx = maxx > s[i].day ? maxx : s[i].day;
}
int sum = 0;
for(int i = 0; i < n; i++)
{
cin >> s[i].score;
sum += s[i].score;
}
sort(s, s + n, cmp);
int temp[maxn] = {false};
for(int i = 0; i < n; i++)
{
for(int j = s[i].day; j>= 0; j--)
{
if(!temp[j])
{
temp[j] = s[i].score;
break;
}
}
}
int m = 0;
for(int i = 1; i <= maxx; i++)
{
m += temp[i];
}
cout <<sum - m << endl;
}
}
return 0;
}