結果

問題 No.914 Omiyage
ユーザー BwambocosBwambocos
提出日時 2019-10-25 21:31:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 178,268 KB
実行使用メモリ 5,932 KB
最終ジャッジ日時 2023-10-24 21:11:02
合計ジャッジ時間 2,509 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
5,932 KB
testcase_01 AC 13 ms
5,932 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 14 ms
5,932 KB
testcase_04 AC 12 ms
5,932 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 13 ms
5,932 KB
testcase_14 AC 14 ms
5,932 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, M, K;
	in >> N >> M >> K;
	std::vector<std::vector<LL>>A(N, std::vector<LL>(M));
	rep(i, N) rep(j, M) in >> A[i][j];

	LL min = 0;
	rep(i, N) min += A[i][0];
	if (min > K)
	{
		out << -1 << std::endl;
		return 0;
	}

	std::vector<LL>v1, v2;
	v1.push_back(0);
	v2.push_back(0);
	rep(i, N / 2)
	{
		std::vector<LL>newV1;
		rep(j, v1.size()) rep(k, M) newV1.push_back(v1[j] + A[i][k]);
		v1 = newV1;
	}
	for (LL i = N / 2; i < N; ++i)
	{
		std::vector<LL>newV2;
		rep(j, v2.size()) rep(k, M) newV2.push_back(v2[j] + A[i][k]);
		v2 = newV2;
	}
	std::sort(v1.begin(), v1.end());
	std::sort(v2.begin(), v2.end());

	LL ans = 0;
	rep(i, v1.size())
	{
		if (v1[i] > K) continue;
		auto it = std::upper_bound(v2.begin(), v2.end(), K - v1[i]);
		if (it != v2.begin()) ans = std::max(ans, v1[i] + *(it - 1));
	}

	out << K - ans << std::endl;
}
0