제출 #1118082

#제출 시각아이디문제언어결과실행 시간메모리
1118082vjudge1Knapsack (NOI18_knapsack)C++14
12 / 100
1 ms336 KiB
#include <bits/stdc++.h> #define sts(v) stable_sort(v.BE, v.E) #define Rsts(v) stable_sort(v.rBE, v.rE) #define rev(v) reverse(v.BE, v.E) #define BE begin() #define rBE rbegin() #define E end() #define rE rend() #define pb push_back #define ppb pop_back() #define pf push_front #define ppf pop_front() #define F first #define S second using namespace std; using ll = long long; struct datos{ int val, w, k; }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int W, n; cin >> W >> n; datos v[n]; for(int i = 0; i < n; i++){ int val, w, k; cin >> val >> w >> k; v[i] = {val, w, k}; } vector<bool> cmp(n); ll ans = 0; while(W){ datos maxi = {0, 0, -1}; bool used = 0; for(int i = 0; i < n; i++){ if(cmp[i])continue; int val = v[i].val, w = v[i].w, k = v[i].k; int _w = 0; ll _val = 0; while(_w + w <= W && k--){ _w += w; _val += val; } if(_val > maxi.val) maxi = {_val, _w, i}; } if(maxi.k != -1){ cmp[maxi.k] = 1; ans += maxi.val; W -= maxi.w; used = 1; } if(!used)break; } cout << ans; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:52:25: warning: narrowing conversion of '_val' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   52 |                 maxi = {_val, _w, i};
      |                         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...