#include using namespace std; int Truck(int m, int *k, int n, int *s, int count) { int i = 0; while (m > 0 && i < n) { if (m >= k[i]) { s[i]++; m -= k[i]; count++; } i++; } return count; } int main() { int n = 5; int m = 20; int count = 0; int k[] = {8, 5, 4, 3, 2}; cout << "n = " << n << endl; cout << "m = " << m << endl; int *s = (int*)calloc(n, sizeof(int)); count = Truck(m, k, n, s, count); cout << "Ket qua: " << count << endl; if (count > 0) { for (int i = 0; i < n; i++) { cout << s[i] << " "; } } return 0; }