Skip the Class
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 350 Accepted Submission(s): 210
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.
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
there should be 1 integer in the line which represents the highest value luras can earn if she choose in the best way.
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<functional>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pI64d(x) printf("%I64d\n",x)
const ll INF=1e15;
const int MOD=1e9+7;
const int N=2e5+10;
const double eps=1e-4;
const double PI=acos(-1.0);
//首先如果想存一個字符串到數組中這時候就該想到用map
struct node
{
int num;
string s;
}a[1001];
int cmp(node a,node b)
{
return a.num>b.num;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
//memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
cin>>a[i].s>>a[i].num;
}
sort(a,a+n,cmp);
int sum=0;
map<string,int>p;//前一個類型是數組下標的類型,後一個類型是數組所存的值
for(int i=0;i<n;i++)
{
p[a[i].s]++;
if(p[a[i].s]<=2)
{
sum+=a[i].num;
}
}
printf("%d\n",sum);
}
}