結果

問題 No.115 遠足のおやつ
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-02-26 16:17:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,482 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 74,276 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-31 00:37:42
合計ジャッジ時間 1,844 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)

#define PI 3.1415926535

typedef long long ll;
typedef pair<int, int> P;
//typedef complex<double> C;

const int MAX_N = 100;
const int MAX_D = 1000;
const int MAX_K = 10;

int N, D, K;
// dp[i][j][k] = i番目までからj個取ったとき、和をkにできるか
// i番目のお菓子は i+1 円
bool dp[MAX_N + 1][MAX_K + 1][MAX_D + 1];

void input() {
	cin >> N >> D >> K;
}

// L円以上N円以下のお菓子からK個選んで和をDにできるか
bool check(int L, int N, int D, int K) {
	if ((N - L + 1) < K) return false;
	int low = 0;
	int high = 0;
	REP(i, K) {
		low += L + i;
		high += N - i;
	}
	return low <= D && high >= D;
}

void solve() {
	if (check(1, N, D, K)) {
		// 安いお菓子から順に調べる
		for (int i = 1; i <= N && K > 0; i++) {
			// i円のお菓子を選ぶことが可能か
			if (check(i + 1, N, D - i, K - 1)) {
				if (K == 1) {
					cout << i << endl;
				} else {
					cout << i << " ";
				}
				D -= i;
				K--;
			}
		}
	} else {
		cout << "-1" << endl;
	}
}

int main() {
	input();
	solve();
}
0