Cod sursa(job #2940313)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 15 noiembrie 2022 11:40:14
Problema Farfurii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;

using namespace std;

/*******************************/
// INPUT / OUTPUT

ifstream f("farfurii.in");
ofstream g("farfurii.out");
/*******************************/
/// GLOBAL DECLARATIONS

ll N, K;
ll cnt;
vector <int> sol;
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    f >> N >> K;
}
///-------------------------------------
inline void Solution()
{
    while ((N - cnt - 1) * (N - cnt - 2) / 2 >= K)
        cnt ++;
    
    for (int i = 1 ; i <= cnt ; ++ i)
        sol.push_back(i);

    int x = (N - cnt) * (N - cnt - 1) / 2 - K, num = N - x;
    if (num > cnt) sol.push_back(num);
    for (int i = N ; i > cnt ; -- i)
        if (i != num) sol.push_back(i);
}
///-------------------------------------
inline void Output()
{
    for (auto x: sol)
        g << x << " ";
}
///-------------------------------------
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ReadInput();
    Solution();
    Output();
    return 0;
}