結果

問題 No.115 遠足のおやつ
ユーザー GOTKAKO
提出日時 2025-07-03 23:30:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 574 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 192,040 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-07-03 23:30:35
合計ジャッジ時間 3,012 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int N,D,K; cin >> N >> D >> K;
    int minK = K*(K+1)/2,maxK = N*(N+1)/2-(N-K)*(N-K+1)/2;
    if(D < minK || maxK < D){cout << -1 << endl; return 0;}
    
    for(int i=1; i<=K; i++){
        maxK -= N-K+i; D -= i;
        if(maxK >= D) cout << i << " ";
        else{
            int more = D-maxK;
            cout << i+more << " ";
            for(int k=i+1; k<=K; k++) cout << N-K+k << " ";
            break;
        }
    }
    cout << endl;
}
0