Doing Homework again

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.

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

题目描述:t组数据,输入n,然后n个数代表要交作业的时间,后边n个数表示作业的分值,做完不扣分,在该交时没交上,要扣对应的分,求最优方案下的扣分。

      先按照分数排序,肯定先安排好分大的,然后再安排分小的。

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std; struct node { //t代表时间,a代表分值
int t, a;
}s[1010]; int T, n, cnt;
bool used[1010]; //标记某个时间段是否用了
bool cmp(node x, node y) {
if (x.a == y.a)
return x.t<y.t;
else
return x.a>y.a;
} int main() {
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> s[i].t;
for (int i = 1; i <= n; i++)
cin >> s[i].a; sort(s + 1, s + n + 1, cmp);
memset(used, false, sizeof(used)); //不要忘了初始化
cnt = 0; for (int i = 1; i <= n; i++) { //枚举,先把分大的安排好
int ans = 1;
for (int j = s[i].t; j>0; j--) { //如果分大的当前时间已经被安排了,那就向前找
if (!used[j]) {
used[j] = true;
ans = 0;
break;
}
}
if (ans)cnt += s[i].a; //找不到,就只能加上
} cout << cnt << "\n";
}
return 0;
}

最新文章

  1. 子div设置浮动无法把父div撑开。
  2. TFS修改项目名称
  3. O(n)线性筛选n以内的素数
  4. 技术英文单词贴--C
  5. Leetcode 130 Surrounded Regions DFS
  6. 一步一步实战扩展 ASP.NET Route,实现小写 URL、个性化 URL
  7. PHP出错界面详细说明
  8. unity3d shader之God Ray上帝之光
  9. eclipse 连接手机的 核心解决办法
  10. mysql之 MySQL 主从基于 GTID 复制原理概述
  11. 同样:Hashtable较HashMap也是如此。
  12. ubuntu1604使用之旅——启动ssh系列
  13. 深入浅出 JVM GC(1)
  14. 国产首款5G手机抢先亮相:如此给力的说!
  15. windows10 hyper-v安装配置centos6.8
  16. windows使用
  17. Spring RedisTemplate操作-HyperLogLog操作(7)
  18. python+stomp+activemq
  19. opencv 摄像头 线程
  20. List&amp;Map&amp;Set的操作和遍历

热门文章

  1. P4053 [JSOI2007]建筑抢修
  2. virtualbox+vagrant学习-2(command cli)-8-vagrant Package命令
  3. centos中安装、升级git
  4. 解决nodejs运行程序卡死之后,程序后台运行的问题
  5. ping不通linux服务器排查
  6. centos安装telnet
  7. jQuery----奇偶选择器和索引选择器
  8. day 85 Vue学习之vue-cli脚手架下载安装及配置
  9. mssqlserver分区表的左值与右值
  10. wp apps