Cod sursa(job #2623100)

Utilizator AvramDanielAvram Daniel AvramDaniel Data 2 iunie 2020 16:53:53
Problema Farfurii Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<bits/stdc++.h>
using namespace std;

int main(){

    ifstream cin("farfurii.in");
    ofstream cout("farfurii.out");

    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;

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

    long long N = (1+ sqrt(1 + 8*k) )/2+1;

    long int K = N*(N - 1)/2;

    for(int i = 1; i<=(n - N);i++)
        cout << i<< ' ';

    int dif = (n - N);
    if(N > K-k)
        cout << N - (K - k) + dif<<' ';

    for(int i = N; i > N - (K - k);i--)
        cout << i + dif <<' ';
    for(long int i = N - (K - k)-1; i>0;i--)
        cout<<i + dif<<' ';

    return 0;
}