Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c;
scanf("%d %d %d %d", &n, &a, &b, &c);
int res = 0;
for(int i = 0; i <= n; ++i)
for(int j = 0; j <= n; ++j) {
int need = n - (i * a + j * b);
if(need >= 0 && need % c == 0)
res = max(res, i + j + need / c);
}
printf("%d\n", res);
return 0;
}
Copy The Code &
Try With Live Editor
Input
5 5 3 2
Output
2
Demonstration
Codeforcess Solution Cut Ribbon, A. Cut Ribbon ,C,C++, Java, Js and Python ,Cut Ribbon,Codeforcess Solution