답안 #18851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
18851 2016-02-16T02:25:00 Z pichulia 컬러볼 (KOI15_ball) C++
25 / 25
130 ms 5000 KB
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
int n, m = 2000;
piii a[200009];
int s[3000];
int b[200009];
int r[200009];
int main() {
	int i, j, k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&a[i].first.second,&a[i].first.first);
		s[a[i].first.first] += a[i].first.first;
		a[i].second = i;
	}
	for(i=1; i<=m; i++)
		s[i] += s[i-1];
	sort(a,a+n);
	for(i=0; i<n; )
	{
		for(j=i+1;j<n;j++)
			if(a[i].first.first != a[j].first.first)
				break;
		for(k=i;k<j;k++)
		{
			r[a[k].second] = s[a[k].first.first - 1] - b[a[k].first.second];
		}
		for(k=i;k<j;k++)
			b[a[k].first.second] += a[k].first.first;
		i=j;
	}
	for(i=0;i<n;i++)
		printf("%d\n",r[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 5000 KB Output is correct
2 Correct 97 ms 5000 KB Output is correct
3 Correct 130 ms 5000 KB Output is correct
4 Correct 62 ms 5000 KB Output is correct
5 Correct 107 ms 5000 KB Output is correct
6 Correct 0 ms 5000 KB Output is correct
7 Correct 3 ms 5000 KB Output is correct
8 Correct 3 ms 5000 KB Output is correct
9 Correct 3 ms 5000 KB Output is correct
10 Correct 4 ms 5000 KB Output is correct
11 Correct 105 ms 5000 KB Output is correct
12 Correct 111 ms 5000 KB Output is correct
13 Correct 124 ms 5000 KB Output is correct
14 Correct 98 ms 5000 KB Output is correct
15 Correct 82 ms 5000 KB Output is correct
16 Correct 73 ms 5000 KB Output is correct
17 Correct 98 ms 5000 KB Output is correct
18 Correct 88 ms 5000 KB Output is correct
19 Correct 105 ms 5000 KB Output is correct
20 Correct 81 ms 5000 KB Output is correct