結果
| 問題 |
No.115 遠足のおやつ
|
| コンテスト | |
| ユーザー |
kichirb3
|
| 提出日時 | 2018-03-19 22:46:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,236 bytes |
| コンパイル時間 | 686 ms |
| コンパイル使用メモリ | 69,388 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2025-01-03 01:27:20 |
| 合計ジャッジ時間 | 2,014 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
// No.115 遠足のおやつ
// https://yukicoder.me/problems/no/115
//
#include <iostream>
#include <vector>
#include <sstream>
#include <numeric>
using namespace std;
vector<int> solve(int N, int D, int K);
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int N, D, K;
cin >> N >> D >> K;
vector<int> ans = solve(N, D, K);
stringstream ss;
for (auto a: ans)
ss << a << " ";
string s = ss.str();
s[s.size()-1] = '\n';
cout << s;
}
vector<int> solve(int N, int D, int K) {
int total_min = (1 + K) * K / 2;
int total_max = (N-K+1 + N) * K / 2;
if (D < total_min)
return vector<int> {-1};
if (D > total_max)
return vector<int> {-1};
vector<int> res(K);
for (int i = 0; i < K; ++i)
res[i] = i+1;
int max_n = N;
int last_r = K - 1;
int diff = D - accumulate(res.begin(), res.end(), 0);
while (diff != 0) {
if (diff <= (max_n - res[last_r])) {
res[last_r] += diff;
break;
}
else {
res[last_r] = max_n;
--max_n;
--last_r;
diff = D - accumulate(res.begin(), res.end(), 0);
}
}
return res;
}
kichirb3