-
Notifications
You must be signed in to change notification settings - Fork 0
/
1055.cpp
61 lines (61 loc) · 1 KB
/
1055.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
#include<iostream>
#include<cstring>
#include<cstdio>
#include <algorithm>
using namespace std;
struct node{
char name[10];
int age,worth;
}a[100005];
int b[20005];
int c[205];
bool cmp(const node& p,const node& q){
if(p.worth==q.worth)
{
if (p.age==q.age)
{
return strcmp(p.name,q.name)<=0;
}
return p.age<q.age;
}
return p.worth>q.worth;
}
int main()
{
int n,q,i,M,ma,mb,txt=1,len;
while(~scanf("%d %d",&n,&q))
{
memset(c,0,sizeof(c));
for (i=0;i<n;++i){
scanf("%s%d%d",a[i].name,&a[i].age,&a[i].worth);
}
sort(a,a+n,cmp);
for (len=i=0;i<n;++i){
if(c[a[i].age]<=100)
{
b[len++]=i;
c[a[i].age]++;
}
}
while(q--){
scanf("%d%d%d",&M,&ma,&mb);
if(ma>mb){
ma^=mb;
mb^=ma;
ma^=mb;
}
printf("Case #%d:\n",txt++);
int cnt=0;
for (i=0;i<len&&cnt<M;++i){
if(a[b[i]].age>=ma&&a[b[i]].age<=mb){
printf("%s %d %d\n",a[b[i]].name,a[b[i]].age,a[b[i]].worth);
cnt++;
}
}
if(cnt==0){
printf("None\n");
}
}
}
return 0;
}