Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- #include <cstdint>
- typedef int16_t Int;
- Int solveSlow(Int max1, Int max2, Int max3, Int perShirt) {
- static Int maxShirts[128][128][128];
- for (Int n1 = 0; n1 <= max1; ++n1) {
- for (Int n2 = 0; n2 <= max2; ++n2) {
- for (Int n3 = 0; n3 <= max3; ++n3) {
- auto& maxSh = maxShirts[n1][n2][n3];
- maxSh = 0;
- Int from = std::min(n3, Int((perShirt+2)/3));
- Int to = std::max(Int(0), Int(from-2));
- for (Int last3 = from; last3 >= to; --last3) {
- Int rem = std::max(Int(0), Int(perShirt-3*last3));
- Int min2 = std::min(n2, Int(rem / 2));
- Int max2 = std::min(n2, Int((rem+1)/2));
- for (Int last2 = min2; last2 <= max2; ++last2) {
- Int last1 = std::max(Int(0), Int(perShirt-3*last3-2*last2));
- if (last1 <= n1) {
- maxSh = std::max(maxSh,Int(maxShirts[n1-last1][n2-last2][n3-last3]+1));
- }
- }
- }
- }
- }
- }
- return maxShirts[max1][max2][max3];
- }
- int main() {
- int n1, n2, n3, perShirt;
- scanf("%d %d %d %d", &n1, &n2, &n3, &perShirt);
- printf("%d", solveSlow(n1, n2, n3, perShirt));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment