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. learning scala output to console

    控制台输出语句: print println example: scala> print("i=");print(i)i=345scala> println(" ...

  2. 架构之路:nginx与IIS服务器搭建集群实现负载均衡(一)

    最近亮亮在研究IIS的负载均衡!本人由于初出茅庐,防骗意识薄弱,一不小心被亮亮坑上了IIS负载均衡之路(亮亮是真黑哈!).前车之鉴啊!小伙伴们要小心.不过既上了贼船,便决定一条道走到黑.于是乎从大前天 ...

  3. HTML编辑笔记1

    1.编写html ①新建一个记事本(以.html结尾) ②右击选择打开方式为文档 ③编写内容 ④用浏览器查看内容 2.html编写格式 <html> <head></he ...

  4. tomcat 线程数与 mysql 连接数综合调优

    目前线上系统包含 数据收集+数据分析+中心服务,三个均为 tomcat,共用一个mysql服务. 由于tomcat最大线程数200 *3 =600,最大并发时,会有600个jdbc连接.当然这是极端情 ...

  5. 每天CSS学习之border-spacing

    border-spacing是CSS2的一个属性.其作用是规定表格的相邻单元格边框之间的距离.如果表格的border-collapse属性值为collapse时,border-spacing设置无效. ...

  6. GFS中文翻译

    Google文件系统 GFS是一个可扩展的分布式文件系统,用于大型的.分布式的.对大量数据进行访问的应用.它运行于廉价的普通硬件上,但可以提供容错功能.它可以给大量的用户提供总体性能较高的服务. 1. ...

  7. php随手记

    引用(&)是变量的别名,而不是指针,可用unset(变量名)把此变量的别名注销掉,等于没有声明此变量. @为错误抑制符,可以用在任何表达式前面. ``为命令操作符,可以执行系统命令. inst ...

  8. jdk8-Optional类

    概念: package com.atguigu.java8; import java.util.Optional; import org.junit.Test; /* * 一.Optional 容器类 ...

  9. python字符串转换成数字

    Action(){ int i; char *s="{str}"; i=atoi(lr_eval_string(s)); lr_output_message("%d&qu ...

  10. cf467D(map,vector,bfs,特点提取)

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...