結果
| 問題 | No.617 Nafmo、買い出しに行く | 
| コンテスト | |
| ユーザー |  noshi91 | 
| 提出日時 | 2017-12-18 18:47:26 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,669 bytes | 
| コンパイル時間 | 983 ms | 
| コンパイル使用メモリ | 90,312 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-16 00:14:56 | 
| 合計ジャッジ時間 | 1,503 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n, k, temp, ans;
	std::cin >> n >> k;
	std::vector<uint32> a(n);
	rep(i, 0, n)
		std::cin >> a[i];
	if (n <= 10) {
		std::vector<uint32> b(1 << n);
		auto itr = b.begin();
		*itr = 0;
		ans = k;
		rep(i, 0, n) {
			temp = 1 << i;
			rep(j, 0, temp) {
				++itr;
				*itr = b[j] + a[i];
				ans = std::min(ans, k - *itr);
			}
		}
		ans = k - ans;
	}
	else {
		std::vector<uint32> b(1 << 10), c(1 << (n - 10));
		auto itr = b.begin();
		*itr = 0;
		rep(i, 0, 10) {
			temp = 1 << i;
			rep(j, 0, temp) {
				++itr;
				*itr = b[j] + a[i];
			}
		}
		itr = c.begin();
		*itr = 0;
		rep(i, 10, n) {
			temp = 1 << (i - 10);
			rep(j, 0, temp) {
				++itr;
				*itr = c[j] + a[i];
			}
		}
		std::sort(c.begin(), c.end(), std::greater<uint32>());
		ans = 0;
		rep(i, 0, 1 << 10) {
			if (b[i] <= k) {
				ans = std::max(ans, b[i] + *std::lower_bound(c.begin(), c.end(), k - b[i], std::greater<uint32>()));
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}
            
            
            
        