Cod sursa(job #2086884)

Utilizator Teodor.mTeodor Marchitan Teodor.m Data 12 decembrie 2017 17:15:37
Problema Farfurii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

inline void debugMode() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("farfurii.in", "r", stdin);
    freopen("farfurii.out", "w", stdout);
    #endif // ONLINE_JUDGE
}
inline void PrintYes() { cout << "Yes"; }
inline void PrintNo() { cout << "No"; }

const double eps = 1e-7;
const int Nmax = 1e5 + 5;

int n, k;
int sol[Nmax];

int find_N(int k)
{
    return (-1 + sqrt(1 + 8 * k)) / 2;
}

int main()
{
    debugMode();

    cin >> n >> k;

    int val = find_N(k);

    int i;
    for(i = 1; i < val; ++i)
        sol[i] = i;

    int temp = k - (val * (val + 1) / 2);
    sol[i] = sol[i - 1] + temp + 1; ++i;
    int k = 0;
    for(; i <= n - temp; ++i)
        sol[i] = n - k, ++k;
    k = 1;
    for(; i <= n; ++i)
        sol[i] = sol[val] - k, ++k;

    for(i = 1; i <= n; ++i)
        cout << sol[i] << " ";
    return 0;
}