結果

問題 No.2567 A_1 > A_2 > ... > A_N
ユーザー elphe
提出日時 2024-07-04 20:43:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 76,044 KB
最終ジャッジ日時 2025-02-22 01:57:57
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int T, i, N, j;
    long long X, sum;
    vector<long long> ans;
    cin >> T;
    for (i = 0; i != T; ++i)
    {
        cin >> N >> X;
        ans.clear();
        sum = N * static_cast<long long>(N + 1) / 2;
        if (sum > X)
        {
            cout << "-1\n";
            continue;
        }

        for (j = 0; j != N; ++j)
            ans.push_back(j + 1 + (X - sum) / N);
        reverse(ans.begin(), ans.end());
        for (j = 0; j != (X - sum) % N; ++j)
            ++ans[j];
        cout << ans[0];
        for (j = 1; j != ans.size(); ++j)
            cout << ' ' << ans[j];
        cout << '\n';
    }

    return 0;
}
0