#include <stdio.h>
#include <algorithm>
using namespace std;
struct data{
int c,s,i;
bool operator<(const data&r)const{
if(s==r.s)return c<r.c;
return s<r.s;
}
}a[200010];
int sum[200010],ans[200010],s;
int main(){
int i,j,n;
scanf("%d",&n);
for(i=1;i<=n;++i)scanf("%d%d",&a[i].c,&a[i].s),a[i].i=i;
sort(a+1,a+n+1);
for(i=2,j=1;i<=n;++i){
while(a[j].s<a[i].s)sum[a[j].c]+=a[j].s,s+=a[j++].s;
ans[a[i].i]=s-sum[a[i].c];
}
for(i=1;i<=n;++i)printf("%d\n",ans[i]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
4988 KB |
Output is correct |
2 |
Correct |
123 ms |
4988 KB |
Output is correct |
3 |
Correct |
101 ms |
4988 KB |
Output is correct |
4 |
Correct |
100 ms |
4988 KB |
Output is correct |
5 |
Correct |
101 ms |
4988 KB |
Output is correct |
6 |
Correct |
0 ms |
4988 KB |
Output is correct |
7 |
Correct |
0 ms |
4988 KB |
Output is correct |
8 |
Correct |
3 ms |
4988 KB |
Output is correct |
9 |
Correct |
2 ms |
4988 KB |
Output is correct |
10 |
Correct |
3 ms |
4988 KB |
Output is correct |
11 |
Correct |
105 ms |
4988 KB |
Output is correct |
12 |
Correct |
80 ms |
4988 KB |
Output is correct |
13 |
Correct |
79 ms |
4988 KB |
Output is correct |
14 |
Correct |
93 ms |
4988 KB |
Output is correct |
15 |
Correct |
82 ms |
4988 KB |
Output is correct |
16 |
Correct |
97 ms |
4988 KB |
Output is correct |
17 |
Correct |
76 ms |
4988 KB |
Output is correct |
18 |
Correct |
108 ms |
4988 KB |
Output is correct |
19 |
Correct |
77 ms |
4988 KB |
Output is correct |
20 |
Correct |
90 ms |
4988 KB |
Output is correct |