結果

問題 No.617 Nafmo、買い出しに行く
ユーザー chocobochocobo
提出日時 2018-08-06 22:46:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 849 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 96,372 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 22:18:17
合計ジャッジ時間 3,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(ll i = 0; i < n; i += k)



int main() {
	int n, k;
	cin >> n >> k;

	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	}

	int ans = 0;
	REP(i, pow(2, n)) {
		int sum = 0;
		REP(j, n) {
			if (i >> j & 1) {
				sum += a[j];
			}
		}
		if (sum <= k) {
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}
0