結果

問題 No.37 遊園地のアトラクション
コンテスト
ユーザー anta
提出日時 2015-09-26 14:48:22
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,159 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 794 ms
コンパイル使用メモリ 104,344 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-26 14:54:56
合計ジャッジ時間 2,735 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int T;
	while(~scanf("%d", &T)) {
		int N;
		scanf("%d", &N);
		vector<int> c(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &c[i]);
		vector<int> v(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &v[i]);
		vector<int> dp(T+1);
		for(int i = 0; i < N; ++ i) {
			int w = v[i];
			while(w > 0) {
				for(int j = T - c[i]; j >= 0; -- j)
					amax(dp[j + c[i]], dp[j] + w);
				w /= 2;
			}
		}
		int ans = *max_element(dp.begin(), dp.end());
		printf("%d\n", ans);
	}
	return 0;
}
0