結果

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

ソースコード

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+1);
    for (int i = 1; i <= k; i++) v[i]++;
    if (diff < 0){
        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 (tk == 0) cout << -1 << endl;
    else {
        string delim = "";
        for (int i = 1; i <= n; i++){
            if (v[i]){
                cout << delim << i;
                delim = " ";
            }
        }
        cout << endl;
    }
}
0