Submission #224423

#TimeUsernameProblemLanguageResultExecution timeMemory
224423MKopchevJob Scheduling (CEOI12_jobs)C++14
100 / 100
357 ms17144 KiB
#include<bits/stdc++.h>
using namespace std;
const int MX=1e6+42;

int n,d,m;

pair<int,int> inp[MX];

bool can(int sz)
{
    int pos=1;

    for(int day=1;day<=n&&pos<=m;day++)
    {
        if(inp[pos].first+d<day)return 0;

        int pos_help=pos;

        while(pos_help<=m&&pos_help-pos<sz&&inp[pos_help].first<=day)
        {
            pos_help++;
        }

        pos=pos_help;
    }

    return pos>m;
}
int main()
{
    scanf("%i%i%i",&n,&d,&m);

    for(int i=1;i<=m;i++)
    {
        scanf("%i",&inp[i].first);
        inp[i].second=i;
    }

    sort(inp+1,inp+m+1);

    int ok=m,not_ok=0;

    while(ok-not_ok>1)
    {
        int av=(ok+not_ok)/2;

        if(can(av))ok=av;
        else not_ok=av;
    }

    printf("%i\n",ok);

    int pos=1;

    for(int day=1;day<=n;day++)
    {
        int pos_help=pos;

        while(pos_help<=m&&pos_help-pos<ok&&inp[pos_help].first<=day)
        {
            printf("%i ",inp[pos_help].second);
            pos_help++;
        }

        pos=pos_help;

        printf("0\n");
    }

    return 0;
}

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i%i",&n,&d,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~~
jobs.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&inp[i].first);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...