제출 #1030483

#제출 시각아이디문제언어결과실행 시간메모리
1030483LmaoLmaoKnapsack (NOI18_knapsack)C++14
0 / 100
3 ms604 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using aa = array<int,3>; const int N = 1e6+5; const int INF = 1e9; struct goods { double avg; ll v; int w; ll k; }; bool cmp(goods a,goods b) { return (a.avg<b.avg); } ll dp[2005]; goods a[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int n,s; cin >> s >> n; for(int i=1;i<=s;i++) { dp[i]=0; } dp[0]=0; for(int i=1;i<=n;i++) { cin >> a[i].v >> a[i].w >> a[i].k; a[i].avg=((a[i].v*1.0)/(a[i].w*1.0)); } sort(a+1,a+1+n,cmp); ll ans=0; for(int i=1;i<=n;i++) { for(ll j=s;j>0;j--) { int m=min(j/a[i].w,a[i].k); if(j>=a[i].w) dp[j]=max(dp[j],dp[j-(m*a[i].w)]+m*a[i].v); ans=max(ans,dp[j]); //cout << dp[j] << ' '; } //cout << endl; } cout << ans; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...