제출 #1321498

#제출 시각아이디문제언어결과실행 시간메모리
1321498NgTrung2217Cloud Computing (CEOI18_clo)C++20
100 / 100
587 ms1460 KiB
#include <bits/stdc++.h> #define task "" #define ff first #define ss second using namespace std; using ll = long long; using pii = pair <int, int>; const char el = '\n'; const char sp = ' '; const int maxN = 100005; const ll INF = 1e16; struct Item { ll c, f, v; int type; }; int n, m; ll dp[maxN + 5]; vector <Item> v; bool compareItems (const Item &a, const Item &b) { if (a.f == b.f) return a.type < b.type; return a.f > b.f; } void solve () { if (!(cin >> n)) return; for (int i = 0;i < n;++i) { ll c, f, v_val; cin >> c >> f >> v_val; v.push_back({c, f, v_val, 0}); } cin >> m; for (int i = 0;i < m;++i) { ll c, f, v_val; cin >> c >> f >> v_val; v.push_back({c, f, v_val, 1}); } sort(v.begin(), v.end(), compareItems); for (int i = 0;i <= maxN;++i) dp[i] = -INF; dp[0] = 0; ll ans = 0; for (auto &it : v) { if (it.type == 1) { for (int i = 0;i + it.c <= maxN;++i) { dp[i] = max(dp[i], dp[i + (int)it.c] + it.v); } } else { for (int i = maxN;i >= it.c;--i) { dp[i] = max(dp[i], dp[i - (int)it.c] - it.v); } } for (int i = 0;i <= maxN;++i) ans = max(ans, dp[i]); } cout << ans << el; } int main () { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } solve(); return 0; }

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

clo.cpp: In function 'int main()':
clo.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(task ".out", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...