Last active
August 31, 2015 19:18
-
-
Save ctylim/9de1c4fe4fc984adf611 to your computer and use it in GitHub Desktop.
yukicoder No.37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
#include <functional> | |
#include <cmath> | |
#include <queue> | |
#include <stack> | |
#define repd(i,a,b) for (int i=(a);i<(b);i++) | |
#define rep(i,n) repd(i,0,n) | |
#define MAX 20 | |
#define NUM 20000 | |
typedef long long ll; | |
using namespace std; | |
int inputValue(){ | |
int a; | |
cin >> a; | |
return a; | |
}; | |
void inputArray(int * p, int a){ | |
rep(i, a){ | |
cin >> p[i]; | |
} | |
}; | |
void inputVector(vector<int> * p, int a){ | |
rep(i, a){ | |
int input; | |
cin >> input; | |
p -> push_back(input); | |
} | |
} | |
template <typename T> | |
void output(T a, int precision) { | |
if(precision > 0){ | |
cout << setprecision(precision) << a << "\n"; | |
} | |
else{ | |
cout << a << "\n"; | |
} | |
} | |
int dp[NUM] = {0}; | |
int main(int argc, const char * argv[]) { | |
// source code | |
int T = inputValue(); | |
int N = inputValue(); | |
vector<int> c; | |
vector<int> v; | |
rep(i, N){ | |
c.push_back(inputValue()); | |
} | |
rep(i, N){ | |
v.push_back(inputValue()); | |
} | |
rep(i, N){ | |
while (v[i] > 0) { | |
for (int j = T - 1; j >= 0; j--) { | |
dp[j + c[i]] = max(dp[j + c[i]], dp[j] + v[i]); | |
} | |
v[i] /= 2; | |
} | |
} | |
int ret = 0; | |
rep(i, T + 1){ | |
ret = max(ret, dp[i]); | |
} | |
output(ret, 0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment