結果

問題 No.115 遠足のおやつ
ユーザー kpinkcat
提出日時 2023-10-23 12:26:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,188 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 195,420 KB
最終ジャッジ日時 2025-02-17 13:17:35
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;

int main(){
    int n, d, k, tn, tk, diff, sum1;
    cin >> n >> d >> k;
    tn = n;
    tk = k;
    sum1 = (1+k)*k/2;
    diff = d - sum1;
    vector<int> v(n+k+1);
    for (int i = 1; i <= k; i++) v[i]++;
    if (diff < 0 || (n*(n+1)/2 < d)){
        cout << -1 << endl;
        return 0;
    } else {
        while (diff && tk){
            if (diff >= (tn - tk)){
                diff -= (tn - tk);
                sum1 += (tn - tk);
                v[tk]--;
                v[tn]++;
                tk--;
                tn--;
            } else {
                sum1 += diff;
                v[tk]--;
                v[diff+tk]++;
                break;
            }
        }
    }
    if (diff && !tk) cout << -1 << endl;
    else {
        string delim = "";
        for (int i = 1; i <= n; i++){
            if (v[i]){
                cout << delim << i;
                delim = " ";
            }
        }
        cout << endl;
    }
}
0