fork download
  1. void Divide(const int st, const int fn, int weight, bool printAnswer = true) {
  2. if (weight == 0) {
  3. return;
  4. }
  5. if (st == fn) {
  6. const int object = objects[st].first / objects[st].second;
  7. while (weight >= object) {
  8. printf("%d\n", object);
  9. weight -= object;
  10. }
  11. } else {
  12. int mid = (st + fn) / 2;
  13. dp[0][0] = 0;
  14. from[0][0] = 0;
  15. for (int i = 1; i <= weight; i++) {
  16. dp[0][i] = INF;
  17. from[0][i] = 0;
  18. }
  19. int now = 0;
  20. for (int i = st; i <= fn; i++) {
  21. now ^= 1;
  22. for (int j = 0; j < objects[i].first; j++) {
  23. from[now][j] = from[now ^ 1][j];
  24. dp[now][j] = dp[now ^ 1][j];
  25. }
  26. for (int j = objects[i].first; j <= weight; j++) {
  27. if (dp[now ^ 1][j] > dp[now ^ 1][j - objects[i].first] + objects[i].second) {
  28. dp[now][j] = dp[now ^ 1][j - objects[i].first] + objects[i].second;
  29. if (i <= mid) {
  30. from[now][j] = j;
  31. } else {
  32. from[now][j] = from[now ^ 1][j - objects[i].first];
  33. }
  34. } else {
  35. dp[now][j] = dp[now ^ 1][j];
  36. from[now][j] = from[now ^ 1][j];
  37. }
  38. }
  39. }
  40. int best = weight;
  41. while (dp[now][best] == INF) {
  42. best--;
  43. }
  44. if (printAnswer) {
  45. printf("%d %d\n", best, dp[now][best]);
  46. }
  47. const int divideWeight = from[now][best];
  48. Divide(st, mid, divideWeight, false);
  49. Divide(mid + 1, fn, best - divideWeight, false);
  50. }
  51. }
  52.  
  53. int main() {
  54. Divide(0, objectIndex - 1, G);
  55. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void Divide(int, int, int, bool)':
prog.cpp:6:28: error: 'objects' was not declared in this scope
         const int object = objects[st].first / objects[st].second;
                            ^
prog.cpp:8:34: error: 'printf' was not declared in this scope
             printf("%d\n", object);
                                  ^
prog.cpp:13:9: error: 'dp' was not declared in this scope
         dp[0][0] = 0;
         ^
prog.cpp:14:9: error: 'from' was not declared in this scope
         from[0][0] = 0;
         ^
prog.cpp:16:24: error: 'INF' was not declared in this scope
             dp[0][i] = INF;
                        ^
prog.cpp:22:33: error: 'objects' was not declared in this scope
             for (int j = 0; j < objects[i].first; j++) {
                                 ^
prog.cpp:26:26: error: 'objects' was not declared in this scope
             for (int j = objects[i].first; j <= weight; j++) {
                          ^
prog.cpp:41:33: error: 'INF' was not declared in this scope
         while (dp[now][best] == INF) {
                                 ^
prog.cpp:45:50: error: 'printf' was not declared in this scope
             printf("%d %d\n", best, dp[now][best]);
                                                  ^
prog.cpp: In function 'int main()':
prog.cpp:54:12: error: 'objectIndex' was not declared in this scope
  Divide(0, objectIndex - 1, G);
            ^
prog.cpp:54:29: error: 'G' was not declared in this scope
  Divide(0, objectIndex - 1, G);
                             ^
stdout
Standard output is empty