Skip the Class

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1028 Accepted Submission(s): 599

Problem Description

Finally term begins. luras loves school so much as she could skip the class happily again.(wtf?)

Luras will take n lessons in sequence(in another word, to have a chance to skip xDDDD).

For every lesson, it has its own type and value to skip.

But the only thing to note here is that luras can’t skip the same type lesson more than twice.

Which means if she have escaped the class type twice, she has to take all other lessons of this type.

Now please answer the highest value luras can earn if she choose in the best way.

Input

The first line is an integer T which indicates the case number.

And as for each case, the first line is an integer n which indicates the number of lessons luras will take in sequence.

Then there are n lines, for each line, there is a string consists of letters from ‘a’ to ‘z’ which is within the length of 10,

and there is also an integer which is the value of this lesson.

The string indicates the lesson type and the same string stands for the same lesson type.

It is guaranteed that——

T is about 1000

For 100% cases, 1 <= n <= 100,1 <= |s| <= 10, 1 <= v <= 1000

Output

As for each case, you need to output a single line.

there should be 1 integer in the line which represents the highest value luras can earn if she choose in the best way.

Sample Input

2

5

english 1

english 2

english 3

math 10

cook 100

2

a 1

a 2

Sample Output

115

3

#include <iostream>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm> using namespace std;
typedef long long ll;
struct cla{
char na[15];
int val;
}a[105];
bool cmp(cla a,cla b) {
return a.val>b.val;
}
int main() {
int t;
map<string,int> mp;
cin>>t;
while(t--) {
mp.clear();
int n;
cin>>n;
ll sum=0;
for(int i=0;i<n;i++) {
scanf("%s%d",a[i].na,&a[i].val);
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++) {
if(mp[a[i].na]==2) continue;
else mp[a[i].na]++;
sum += a[i].val;
}
printf("%lld\n",sum);
}
return 0;
}

HDU 6015 Skip the Class 优先队列 map的使用的更多相关文章

  1. HDU 6015 Skip the Class

    Skip the Class 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define l ...

  2. (bc 1001) hdu 6015 skip the class

    Skip the Class Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  3. HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)

    题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...

  4. hdu 5437 Alisha’s Party 优先队列

    Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...

  5. HDU 5884 Sort(二分+优先队列)

    http://acm.hdu.edu.cn/showproblem.php?pid=5884 题意:有个屌丝设计了一个程序,每次可以将k个数组进行合并,代价为这k个数组总的长度之和.现在另外一个屌丝要 ...

  6. HDU 4974 Dracula and Ethan 优先队列

    Dracula and Ethan Time Limit: 1 Sec  Memory Limit: 256 MB Description Dragon is watching competition ...

  7. [HDU] 2094 产生冠军(拓扑排序+map)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2094 注意每组数据处理前,map要清空. #include<cstdio> #includ ...

  8. hdu 2757 Ocean Currents(优先队列+bfs)

    小伙伴们真心被这道题惊呆了!刚开始是读题,题目都把小伙伴惊呆了,题目都读不懂! 在前面猴子小伙伴的帮助下,理解了一点点,又偷偷的在纸上写写画画,明白了题意! 后来,你懂的,果断拿下!在拿下的过程也经过 ...

  9. hdu 1263 水果 【二维map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 题目大意: Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ ...

随机推荐

  1. Redis分布式锁实例

    maven依赖 <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</ ...

  2. 原 spring-boot工程中,jpa下hibernate的ddl-auto的各种属性

    jpa:  hibernate:    ddl-auto: create ddl-auto:create----每次运行该程序,没有表格会新建表格,表内有数据会清空 ddl-auto:create-d ...

  3. tocat 域名绑定

    修改tomcat/conf/server.xml配置文件,新增部分如下 <Service name="Catalina1"> <Connector port=&q ...

  4. flask项目结构(五)使用数据库

    简介: 基础搭建好了,开始读写数据库吧.毕竟写的程序,也没什么高深的,就是CRUD,中文说是增删改查. 一:在数据库中增加测试数据. 在项目根目录建立init_test.py from config ...

  5. sass 继承 占位符 %placeholder

    @extend //SCSS .btn { border: 1px solid #ccc; padding: 6px 10px; font-size: 14px; } .btn-primary { b ...

  6. Linux文件管理常用命令用法总结

    1.touch change file timestamps. 命令用于修改文件或者目录的时间属性,包括存取时间和更改时间.若文件不存在,系统会建立一个新的文件.stat,ls -l 可以显示档案的时 ...

  7. 201621123001 《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰 ...

  8. 解决Cannot resolve reference to bean 'txPointcut' while setting bean property 'pointcut'

    忘记导入了 这三个jar包...

  9. js基础 三种弹出框 数据类型

    总结:js三个组成部分ES:语法DOM:对象模型 => 通过js代码与页面文档(出现在body中的所有可视化标签)进行交互BOM:对象模型 => 通过js代码与浏览器自带功能进行交互 引入 ...

  10. kbmMWUnidac直接SQLServer

    UniDAC支持SQLServer直联了,当时就测试过在kbmMW中用直联方式,结果不尽人意,kbmMWServer在执行sql时会出地址错误,就一直没有进一步测试.今天听xalion说,是因为当直联 ...