Submission #788979

#TimeUsernameProblemLanguageResultExecution timeMemory
788979codergirlKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include <cstdio> #include <cmath> int main() { long v[1000000], w[1000000]; int s, n; std::scanf("%d %d", &y, &z, &x); long counter = 0, t; int x, y, z; for (int i=0; i < n; i++) { std::scanf("%d %d %d", &y, &z, &x); for (int j=0; j < 30; j++) { if (x == 0) break; t = std::pow(2, j); if (z*t > s) break; if (x < t) { v[counter] = y*x, w[counter++] = z*x; break; } v[counter] = y*t, w[counter++] = z*t; x -= t; } } long arr[2][s+1]; for (long j=0; j <= s; j++) arr[0][j] = 0; arr[1][0] = 0; int a=0, b=1; for (long i=1; i <= counter; i++) { a = 1-a, b = 1-b; for (long j=1; j <= s; j++) arr[a][j] = (j-w[i-1] >= 0) ? std::max(arr[b][j-w[i-1]]+v[i-1], arr[b][j]) : arr[b][j]; } printf("%d\n", arr[a][s]); }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:5:65: error: 'y' was not declared in this scope
    5 |     long v[1000000], w[1000000]; int s, n; std::scanf("%d %d", &y, &z, &x);
      |                                                                 ^
knapsack.cpp:5:69: error: 'z' was not declared in this scope
    5 |     long v[1000000], w[1000000]; int s, n; std::scanf("%d %d", &y, &z, &x);
      |                                                                     ^
knapsack.cpp:5:73: error: 'x' was not declared in this scope
    5 |     long v[1000000], w[1000000]; int s, n; std::scanf("%d %d", &y, &z, &x);
      |                                                                         ^
knapsack.cpp:31:72: error: 'max' is not a member of 'std'; did you mean 'fmax'?
   31 |         for (long j=1; j <= s; j++) arr[a][j] = (j-w[i-1] >= 0) ? std::max(arr[b][j-w[i-1]]+v[i-1], arr[b][j]) : arr[b][j];
      |                                                                        ^~~
      |                                                                        fmax
knapsack.cpp:34:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=]
   34 |     printf("%d\n", arr[a][s]);
      |             ~^     ~~~~~~~~~
      |              |             |
      |              int           long int
      |             %ld