Cod sursa(job #1511043)

Utilizator serbanSlincu Serban serban Data 25 octombrie 2015 22:45:40
Problema Farfurii Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <bits/stdc++.h>

using namespace std;

bool c[100005];

int main()
{
    freopen("farfurii.in", "r", stdin);
    freopen("farfurii.out", "w", stdout);

    int n, k;
    cin >> n >> k;

    int last = 1;
    for(int i = 1; i <= n; i ++) {
        int j = n - i - 1;
        int nxt = j * (j + 1) / 2;
        if(nxt >= k) {
            cout << last << " ";
            c[last] = true;
            while(c[last])
                last ++;
        }
        else {
            int j = k - nxt;
            int in = last;
            while(j) {
                if(!c[last])
                    j --;
                last ++;
            }
            while(c[last])
                last ++;
            k = nxt;
            cout << last << " ";
            c[last] = true;
            last = in;
        }
    }
    cout << "\n";
    return 0;
}