結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
|
提出日時 | 2022-10-01 05:01:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 813 bytes |
コンパイル時間 | 2,099 ms |
コンパイル使用メモリ | 195,124 KB |
最終ジャッジ日時 | 2025-02-07 20:00:37 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); // [L, R] から K 個選んで D を作ることができるか auto f = [](int L, int R, int D, int K) { if(R - L + 1 < K) return false; int MIN = + K * (K + 2 * L - 1) / 2; int MAX = - K * (K - 2 * R - 1) / 2; return MIN <= D && D <= MAX; }; int N,D,K; cin >> N >> D >> K; if(!f(1, N, D, K)) { cout << -1 << endl; return 0; } vector<int> ans; for(int x = 1; x <= N; x++) { if(f(x + 1, N, D - x, K - 1)) { D -= x; K -= 1; ans.push_back(x); } } for(int a : ans) cout << a << " "; cout << endl; }