qkskskn   6년 전

#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

struct date {
int index;
int color;
int size;
int point;
bool operator < (date other) {
return size < other.size;
}
};
bool cmp(date a, date b) {
return a.index < b.index;
}

date ball[200001];
int updatecolor[200001] = { 0 };
int sizecount[2001] = { 0 };

int main() {
int n, c, s, sum = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c >> s;
ball[i].index = i;
ball[i].color = c;
ball[i].size = s;
}
sort(ball + 1, ball + n + 1);
for (int i = 1; i <= n; i++) {
sum += ball[i].size;
updatecolor[ball[i].color] += ball[i].size;
sizecount[ball[i].size]++;
if (sizecount[ball[i].size] > 1 && ball[i - 1].color != ball[i].color)
ball[i].point = sum - updatecolor[ball[i].color] - (sizecount[ball[i].size] - 1)*ball[i].size;
else
ball[i].point = sum - updatecolor[ball[i].color];
}
sort(ball + 1, ball + n + 1, cmp);
for (int i = 1; i <= n; i++)
cout << ball[i].point << '\n';
}


댓글을 작성하려면 로그인해야 합니다.