Submission #51606

#TimeUsernameProblemLanguageResultExecution timeMemory
51606baneling100컬러볼 (KOI15_ball)C++17
25 / 25
226 ms40848 KiB
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector<pair<int, int>> Csum[200001];
int N, C[200001], S[200001], Ssum[2001];

int findCsum(int x, int y) {
    int left = 0, mid, right = Csum[x].size() - 1, value = 0;

    while(left <= right) {
        mid = (left + right) / 2;
        if(y < Csum[x][mid].first) right = mid - 1;
        else {
            value = Csum[x][mid].second;
            left = mid + 1;
        }
    }
    return value;
}

int main() {

    int i, j, k;

    scanf("%d", &N);
    for(i = 1; i <= N; i++) {
        scanf("%d %d", &C[i], &S[i]);
        Csum[C[i]].push_back(make_pair(S[i], S[i]));
        Ssum[S[i]] += S[i];
    }
    for(i = 1; i <= N; i++) {
        sort(Csum[i].begin(), Csum[i].end());
        k = Csum[i].size();
        for(j = 1; j < k; j++) Csum[i][j].second += Csum[i][j - 1].second;
    }
    for(i = 1; i <= 2000; i++) Ssum[i] += Ssum[i - 1];

    for(i = 1; i <= N; i++) printf("%d\n", Ssum[S[i] - 1] - findCsum(C[i], S[i] - 1));

    return 0;
}

Compilation message (stderr)

ball.cpp: In function 'int main()':
ball.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
ball.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &C[i], &S[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...