Skip to content

Instantly share code, notes, and snippets.

@benblack769
Created October 9, 2016 20:25
Show Gist options
  • Save benblack769/a793c849d29129986a9e961bf83a4454 to your computer and use it in GitHub Desktop.
Save benblack769/a793c849d29129986a9e961bf83a4454 to your computer and use it in GitHub Desktop.
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
typedef long long LL;
LL cube(LL x){
return x*x*x;
}
LL sqr(LL x){
return x*x;
}
LL calculate_volume(LL b, LL t, LL h, LL brick_size, LL c_h){
LL num = (b*h - (((b-t)*(c_h+brick_size))))/(brick_size*h);
return LL(num) * LL(num) * LL(brick_size) * LL(brick_size) * LL(brick_size);
}
constexpr size_t maxn = 1000000+1;
LL table[maxn] = {0};
int main(){
int h,b,t;
vi bricks(3,0);
for (auto &x:table){
x = -1;
}
while (cin >> h >> b >> t >> bricks[0] >> bricks[1] >> bricks[2]){
table[0] = 0;
for(int i = 0; i < h+1; i++){
if(table[i] != LL(-1)){
//cout << table[i] << endl;
for(int j = 0; j < 3; j++){
if (i+bricks[j] <= h){
LL vol = calculate_volume(b,t,h,bricks[j],i);
table[i+bricks[j]] = max(vol+table[i],table[i+bricks[j]]);
}
}
}
/*if(table[i] != -1){
LL max_tmp = 0;
for(int j = 0; j < 3; j++){
if (i>=bricks[j] and table[i-bricks[j]]>=0){
LL vol = calculate_volume(b,t,h,bricks[j],i);
max_tmp = max(vol+table[i-bricks[j]],max_tmp);
}
}
table[i] = max_tmp;
}*/
}
//cout << calculate_volume(100, 50, 100, 11, 13) << endl;
cout << *max_element(table, table+h+1) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment