杭电 1789 Doing Homework again (贪心 求最少扣分)
2024-08-30 20:01:59
Description
zichen 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 zichen 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 zichen 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
#include<cstdio>
#include<algorithm>
using namespace std;
struct stu
{
int d,s;
}a[];
bool cmp(stu a,stu b)
{
if(a.s != b.s) return a.s>b.s;
else return a.d<b.d;
}
int main()
{ int t,n,j;
scanf("%d",&t);
while(t--)
{
int b[]={,};
int sum=;
scanf("%d",&n);
for(int i = ; i < n; i++)
{
scanf("%d",&a[i].d);
}
for(int i = ; i < n; i++)
{
scanf("%d",&a[i].s);
}
sort(a,a+n,cmp); /* for(int i = 0;i < n;i++)
printf("--%d--%d--\n",a[i].d,a[i].s);
*/ for(int i=;i<n;i++)
{
for(j=a[i].d;j>;j--)
{
if(b[j] == )
{
b[j]=;
break;
}
}
if(j == ) sum+=a[i].s;
}
printf("%d\n",sum);
}
}
最新文章
- [原]分享一下我和MongoDB与Redis那些事
- BrnShop mvc3升级mvc4
- MyCAT实现MySQL的读写分离
- How to create a project with Oracle Policy Modeling
- Android官方提供的下拉刷新控件——SwipeRefreshLayout
- HDU 1394Minimum Inversion Number(线段树)
- java程序练习:x进制转Y进制
- Dijkstra in python
- Loadrunner负载机agent
- Bash判断是否是root
- Python for else 循环控制
- verilog中always块延时总结
- Git 忽略特殊文件的功能
- [LeetCode] 33. Search in Rotated Sorted Array_Medium tag: Binary Search
- 用NextResult方法取得多个Result Set
- 在不安装oracle客户端的情况下,使用PLSQL
- 利用反射C#获取事件列表
- 24.ArrayBuffer
- Unity3d游戏开发中使用可空类型(Nullable Types)
- 一些有趣的使用function