Submission #18038

#TimeUsernameProblemLanguageResultExecution timeMemory
18038gs14004컬러볼 (KOI15_ball)C++14
25 / 25
119 ms7188 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <limits.h> #include <stack> #include <queue> #include <map> #include <set> #include <algorithm> #include <string> #include <functional> #include <vector> #include <numeric> #include <deque> #include <bitset> #include <iostream> using namespace std; typedef long long lint; typedef long double llf; typedef pair<int, int> pi; lint ret[200005]; lint sum[200005], fsum; struct elem{int c, s, i;}a[200005]; int n; int main(){ scanf("%d",&n); for(int i=0; i<n; i++){ scanf("%d %d",&a[i].c, &a[i].s); a[i].i = i; } sort(a, a+n, [&](const elem &a, const elem &b){ return a.s < b.s; }); for(int i=0; i<n; i++){ int e = i; while(e < n && a[e].s == a[i].s) e++; for(int j=i; j<e; j++){ ret[a[j].i] = fsum - sum[a[j].c]; } for(int j=i; j<e; j++){ fsum += a[j].s; sum[a[j].c] += a[j].s; } i = e-1; } for(int i=0; i<n; i++){ printf("%lld\n",ret[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...