Submission #18053

#TimeUsernameProblemLanguageResultExecution timeMemory
18053chan492811컬러볼 (KOI15_ball)C++98
25 / 25
117 ms4988 KiB
#include <cstdio> #include <algorithm> using namespace std; int n,sum; struct data{ int z,x,idx; }; data arr[200010]; int index[200010],color[200010]; bool compare(data d1,data d2){ return d1.x<d2.x; } int main(){ int i,j,cnt; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d %d",&arr[i].z,&arr[i].x),arr[i].idx=i; sort(arr+1,arr+n+1,compare); j=0; for(i=1;i<=n;i++){ if(arr[i].x!=arr[i-1].x){ for(;j<i;j++) sum+=arr[j].x, color[arr[j].z]+=arr[j].x; } index[arr[i].idx]=sum-color[arr[i].z]; } for(i=1;i<=n;i++) printf("%d\n",index[i]); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...