結果

問題 No.115 遠足のおやつ
ユーザー masamasa
提出日時 2015-11-12 21:18:44
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,025 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 66,704 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-03 01:07:38
合計ジャッジ時間 1,992 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
	int n, d, k;

	cin >> n >> d >> k;

	if (n < k) {
		cout << -1 << endl;
		return 0;
	}

	vector<int> bought;
	int d_rest = d;
	int k_rest = k;
	int partial_max = 0;
	int partial_min = 0;

	for (int i = 0; i < k - 1; i++) {
		partial_min += i + 1;
		partial_max += n - i;
	}

	for (int i = 1; i <= n; i++) {
		int tmp_rest = d_rest - i;

// printf("%2d tmp_rest %2d, k_rest %d, partial %2d - %2d\n", i, tmp_rest, k_rest, partial_min, partial_max);
		if (tmp_rest < partial_min || partial_max < tmp_rest) {
			partial_min += k_rest - 1;
			continue;
		}
// printf("push_back %d\n", i);

		bought.push_back(i);
		d_rest = tmp_rest;
		k_rest--;

		partial_min -= i;
		partial_max -= n - (k_rest - 1);
	}



	if (bought.size() != k) {
		cout << -1 << endl;
	} else {
		for (int i = 0; i < k; i++) {
			if (i != 0) {
				cout << " ";
			}
			cout << bought[i];
		}
		cout << endl;
	}

	return 0;
}
0