Cod sursa(job #3231755)

Utilizator RaresStanStan Rares RaresStan Data 27 mai 2024 17:43:46
Problema Farfurii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <bits/stdc++.h>
#define NMAX 100005
#define pb push_back
#define int long long
using namespace std;
vector<int>r;
int f[NMAX], op, n, k, lasti;
bool cond(int x)
{
    if(op + (n - lasti) * (n - lasti - 1) /2 >= k)
        return true;
    else
        return false;
}
signed main()
{
    ifstream cin("farfurii.in");
    ofstream cout("farfurii.out");
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> k;
    bool enter = false;
    for(int i = 1; i <= n; i++)
    {
        if((n - i) * (n - i - 1) /2 >= k && enter == false)
            r.pb(i),f[i]++;
        else enter = true;
        if(enter == true){
            lasti = i;
            while(!cond(i) && i <= n)
                i++, op++;
            r.pb(i),f[i]++;
            break;
        }
    }
    for(int i = n; i >= 1 ; i--)
        if(f[i] == 0) r.pb(i);
    for(int x : r)
        cout << x << " ";
    return 0;
}