Submission #738977

#TimeUsernameProblemLanguageResultExecution timeMemory
738977vjudge1Job Scheduling (CEOI12_jobs)C++17
0 / 100
277 ms17264 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pi3 = pair<int,pii>;

#define ON(n , k) ( (n) | ( 1 << (k) ))
#define OFF(n ,k) ( (n) & ( ~( 1 << (k))))
#define ISON(n ,k) ( ( (n)>>(k) ) & (1) )
#define F first
#define S second



const int N = 2e5+5;
const int mod = 1e9+7;
const int INF = 1e9+9;
const double PI = 3.1415926536;
int dx[10] = {0,  0, 1, -1, 1,  1, -1, -1, 0};
int dy[10] = {1, -1, 0,  0, 1, -1,  1, -1, 0};
char str[N];


int n, d, m;
vector<pii>v;

bool cmp(pii A, pii B)
{
    if(A.S == B.S)
    {
        return B.F < A.F;
    }

    return A.S < B.S;
}


bool ok(int mid)
{
    int j = 1, i = 0;
    while(i < m)
    {
        int s = i;
        for(i; i < s + mid; i++)
        {

            if( (j - v[i].S) > d)return false;

        }
        j++;
    }

    return true;
}

void solve()
{
    scanf("%d%d%d", &n, &d, &m);

    for(int i = 1; i <= m; i++)
    {
        int x;
        scanf("%d", &x);
        v.push_back({i, x});
    }

    sort(v.begin(), v.end(), cmp);



    int l = 0, r = m+2, mid;


    while(l + 1 < r)
    {
        mid = l + (r - l)/2;
        if(ok(mid))
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }

    printf("%d\n", r);

    int j = 1, i = 0;
    while(j <= n)
    {
        int s = i;
        for(i; i < s + mid && i < m; i++)
        {

            printf("%d ", v[i].F);

        }
        j++;

        printf("0\n");
    }


}

int main()
{

    //freopen("", "r", stdin);
    //freopen("", "w", stdout);

    /*
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    */
    int T;
    T = 1 ;
    //scanf("%d" , &T);

    while(T--)
    {
        // init();
        solve();
    }

    return 0;
}

Compilation message (stderr)

jobs.cpp: In function 'bool ok(int)':
jobs.cpp:45:13: warning: statement has no effect [-Wunused-value]
   45 |         for(i; i < s + mid; i++)
      |             ^
jobs.cpp: In function 'void solve()':
jobs.cpp:94:13: warning: statement has no effect [-Wunused-value]
   94 |         for(i; i < s + mid && i < m; i++)
      |             ^
jobs.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     scanf("%d%d%d", &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
jobs.cpp:94:22: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   94 |         for(i; i < s + mid && i < m; i++)
      |                    ~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...