-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.cpp
95 lines (92 loc) · 2.04 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2013-11-21-22.04
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long(LL);
typedef unsigned long long(ULL);
const double eps(1e-8);
const int MAXN=150010;
int k,m,n,val[MAXN];
char name[MAXN][205];
int th[MAXN],let[MAXN],ans[MAXN];
struct op_dr
{
int th,let;
bool operator<(const op_dr& a)const
{
return th<a.th;
}
}op[MAXN];
struct val_id
{
int val,id;
bool operator<(const val_id& a)const
{
return val>a.val ||(val==a.val && id<a.id);
}
} vi[MAXN];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&k,&m,&n);
for(int i=1;i<=k;++i)
{
scanf("%s %d",name[i],&vi[i].val);
vi[i].id=i;
}
for(int i=1;i<=m;++i)
{
scanf("%d %d",&op[i].th,&op[i].let);
}
op[m+1].th=k,op[m+1].let=k;
sort(op+1,op+2+m);
int cnt=1;
int num=1;
multiset<val_id> ms;
for(int i=1;i<=m+1;++i)
{
while(cnt<=op[i].th)
{
ms.insert(vi[cnt++]);
}
int in=1;
while(in<=op[i].let && ms.size()>0)
{
val_id tmp=*ms.begin();
ms.erase(ms.begin());
ans[num++]=tmp.id;
++in;
}
}
int tmp;
for(int i=1;i<=n;++i)
{
scanf("%d",&tmp);
printf(i==n?"%s\n":"%s ",name[ans[tmp]]);
}
}
return 0;
}
/*
*/