Submission #230748

#TimeUsernameProblemLanguageResultExecution timeMemory
230748Ruxandra985Job Scheduling (CEOI12_jobs)C++14
100 / 100
344 ms17144 KiB
#include <bits/stdc++.h>

using namespace std;
int d , n , m;
pair <int,int> v[1000010];

int check (int x , int type){

    int today , days , put , i , sol = 0;

    if (type)
        printf ("%d\n",x);

    today = 0;
    days = 1;

    for (i = 1 ; i <= n ; i++){

        put = 0;

        if (days >= v[i].first && today + 1 <= x){
            today++;
            sol = max(sol , days - v[i].first);
            if (type == 1)
                printf ("%d " ,v[i].second);
            put = 1;
        }
        else if (today + 1 > x){
            today = 0;
            days++;
            if (type)
                printf ("0\n");
        }

        if (!put){
            while (days < v[i].first){
                days++;
                today = 0;
                if (type)
                    printf ("0\n");
            }
            if (type)
                printf ("%d ",v[i].second);
            today++;
            sol = max(sol , days - v[i].first);
        }


    }


    if (type){

        while (days <= m){

            printf ("0\n");
            days++;

        }

    }

    if (days <= m && sol <= d)
        return 1;
    return 0;


}

int main()
{
    FILE *fin = stdin;
    int i , st , dr , mid;
    fscanf (fin,"%d%d%d",&m,&d,&n);

    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d",&v[i].first);
        v[i].second = i;
    }
    sort (v + 1 , v + n + 1);

    st = 1;
    dr = n;

    while (st <= dr){
        mid = (st + dr)/2;

        if (check(mid , 0))
            dr = mid - 1;
        else st = mid + 1;
    }

    check (st , 1);

    return 0;
}

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:74:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d%d",&m,&d,&n);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:77:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&v[i].first);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...