Submission #141235

# Submission time Handle Problem Language Result Execution time Memory
141235 2019-08-07T07:21:12 Z Ruxandra985 Hokej (COCI17_hokej) C++14
120 / 120
213 ms 6480 KB
#include <cstdio>
#include <algorithm>
#define DIMN 500010

using namespace std;
int cmp (pair <int , pair <int,int> > x , pair <int , pair <int,int> > y){
    if (x.first != y.first)
        return x.first > y.first;
    return x.second.first < y.second.first;
}
struct idk{
    int time,idx,col;
} changes[4*DIMN];
pair <int, pair <int,int> > v[DIMN];
int last[7],ok[10];
int cmp2 (idk x, idk y){
    if (x.time != y.time)
        return x.time < y.time;
    else return x.idx < y.idx;
}
int next (int start){
    while (ok[start])
        start++;
    return start;
}
int main()
{
    //freopen ("a.in" , "r" , stdin);
    //freopen ("a.out" , "w" , stdout);
    int sum, elem,start,i,n,m;
    long long score;
    scanf ("%d%d",&m,&n);
    for (i=1;i<=n;i++){
        scanf ("%d%d",&v[i].first , &v[i].second.first);
        v[i].second.second = i;
    }
    sort (v+1 , v + n + 1,cmp);
    sum = 0;
    score = 0;
    start = 1;
    ok[1] = 1;
    elem = 0;
    for (i=1 ; i<=n ; i++){


        if (v[i].second.first == m){
            //printf ("%d\n",v[i].second.second);
            if (!sum){
                score = score + (long long)v[i].first * v[i].second.first;
                elem++;
                changes[elem].time = 0; /// dupa sum minute
                changes[elem].idx = v[i].second.second; /// pe asta il pui
                changes[elem].col = start;
                ok[start] = 1;
                start=next(start);
                if (start == 7)
                    break;
                continue;
            }
            else if (next(start)<=6){
                score = score + (long long)v[i].first * v[i].second.first;
                elem++;
                changes[elem].time = 0; /// dupa sum minute
                changes[elem].idx = v[i].second.second; /// pe asta il pui
                changes[elem].col = next(start);
                ok[next(start)] = 1;
                continue;
            }
            else v[i].second.first--;
        }
        score = score + (long long)v[i].first * min ( v[i].second.first , m - sum);
        if (sum + min ( v[i].second.first , m - sum) == m){
            elem++;
            changes[elem].time = sum; /// dupa sum minute
            changes[elem].idx = v[i].second.second; /// pe asta il pui
            changes[elem].col = start;
            /// din v[i], in start pui doar m - sum
            start=next(start);
            ok[start] = 1;
            if (start == 7)
                break;
            v[i].second.first -= min ( v[i].second.first , m - sum);
            sum = 0;
            if (v[i].second.first)
                i--;
        }
        else {
            elem++;
            changes[elem].time = sum; /// dupa sum minute
            changes[elem].idx = v[i].second.second; /// pe asta il pui
            changes[elem].col = start;
            /// pe coloana start, ai jucatorul i fully
            int ant = v[i].second.first;
            v[i].second.first -= min ( v[i].second.first , m - sum);
            sum = sum + min ( ant , m - sum);
        }

    }
    printf ("%lld\n",score);
    sort (changes+1 , changes + elem + 1, cmp2);
    int ok = 0;
    for (i=1;i<=elem;i++){
        if (changes[i].time == 0){ /// jucator initial
            printf ("%d ",changes[i].idx);
            last[changes[i].col] = changes[i].idx;
            ok++;
            if (ok == 6){
                printf ("\n%d\n",elem-6);
            }
        }
        else {
            printf ("%d %d %d\n",changes[i].time , last[changes[i].col] , changes[i].idx);
            last[changes[i].col] = changes[i].idx;
        }
    }
    return 0;
}

Compilation message

hokej.cpp: In function 'int main()':
hokej.cpp:32:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d%d",&m,&n);
     ~~~~~~^~~~~~~~~~~~~~
hokej.cpp:34:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d%d",&v[i].first , &v[i].second.first);
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 4 ms 380 KB Output is correct
3 Correct 11 ms 632 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 43 ms 1676 KB Output is correct
9 Correct 213 ms 6412 KB Output is correct
10 Correct 212 ms 6480 KB Output is correct