제출 #1108324

#제출 시각아이디문제언어결과실행 시간메모리
1108324expert007Knapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
void solve() { int s, n; cin >> s >> n; vector<int> v(n), w(n), k(n); for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } if (n == 1) { int maxi = 0; for (int i = 1; i <= k[0]; i++) { int total_weight = w[0] * i; int total_value = v[0] * i; if (total_weight <= s) { maxi = max(maxi, total_value); } else { break; } } cout << maxi << endl; } }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'void solve()':
knapsack.cpp:3:5: error: 'cin' was not declared in this scope
    3 |     cin >> s >> n;
      |     ^~~
knapsack.cpp:5:5: error: 'vector' was not declared in this scope
    5 |     vector<int> v(n), w(n), k(n);
      |     ^~~~~~
knapsack.cpp:5:12: error: expected primary-expression before 'int'
    5 |     vector<int> v(n), w(n), k(n);
      |            ^~~
knapsack.cpp:7:16: error: 'v' was not declared in this scope
    7 |         cin >> v[i] >> w[i] >> k[i];
      |                ^
knapsack.cpp:7:24: error: 'w' was not declared in this scope
    7 |         cin >> v[i] >> w[i] >> k[i];
      |                        ^
knapsack.cpp:7:32: error: 'k' was not declared in this scope
    7 |         cin >> v[i] >> w[i] >> k[i];
      |                                ^
knapsack.cpp:13:30: error: 'k' was not declared in this scope
   13 |         for (int i = 1; i <= k[0]; i++) {
      |                              ^
knapsack.cpp:14:32: error: 'w' was not declared in this scope
   14 |             int total_weight = w[0] * i;
      |                                ^
knapsack.cpp:15:31: error: 'v' was not declared in this scope
   15 |             int total_value = v[0] * i;
      |                               ^
knapsack.cpp:18:24: error: 'max' was not declared in this scope; did you mean 'maxi'?
   18 |                 maxi = max(maxi, total_value);
      |                        ^~~
      |                        maxi
knapsack.cpp:23:9: error: 'cout' was not declared in this scope
   23 |         cout << maxi << endl;
      |         ^~~~
knapsack.cpp:23:25: error: 'endl' was not declared in this scope
   23 |         cout << maxi << endl;
      |                         ^~~~