Created
May 28, 2015 01:25
-
-
Save hanjae-jea/79318d53d55347a16a2d to your computer and use it in GitHub Desktop.
도전 과제 풀기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int n; | |
int color_weight[2005]; | |
unsigned int answer[2005]; | |
vector< pair<int,int> > table[2005]; | |
void input(); | |
void proc(); | |
void output(); | |
void input() | |
{ | |
int color, weight; | |
FILE *fin = fopen("input.txt", "r"); | |
fscanf(fin, "%d", &n); | |
for( int i = 0 ; i < n ; i ++ ){ | |
fscanf(fin, "%d %d", &color, &weight); | |
table[weight].push_back(make_pair(color, i)); | |
} | |
fclose(fin); | |
} | |
void proc() | |
{ | |
unsigned long long weight_of_all = 0; | |
for( int i = 1 ; i <= 2000 ; i ++ ){ | |
if( !table[i].empty() ){ | |
int j, len; | |
for( j = 0, len = table[i].size() ; j < len ; j ++ ){ | |
answer[ table[i][j].second ] = weight_of_all - color_weight[ table[i][j].first ]; | |
color_weight[ table[i][j].first ] += i; | |
} | |
weight_of_all += i * len; | |
} | |
} | |
} | |
void output() | |
{ | |
FILE *fout = fopen("output.txt", "w"); | |
for( int i = 0 ; i < n ; i ++ ){ | |
fprintf(fout, "%d\n", answer[i]); | |
} | |
fclose(fout); | |
} | |
int main(void) | |
{ | |
input(); | |
proc(); | |
output(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment