Submission #1268781

#TimeUsernameProblemLanguageResultExecution timeMemory
1268781MinhKienCloud Computing (CEOI18_clo)C++20
0 / 100
2 ms3400 KiB
#include <algorithm> #include <iostream> #include <cstring> using namespace std; #define ll long long const int N = 4010; const ll INF = 1e17; struct object { int room, f; ll cost; bool operator < (const object &o) const { if (f == o.f) return cost > o.cost; return f > o.f; } } a[N]; int n, m; ll dp[2][50 * N]; int main() { #define tst "DATPHONG" freopen(tst".INP", "r", stdin); freopen(tst".OUT", "w", stdout); cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i].room >> a[i].f >> a[i].cost; a[i].cost *= -1; } cin >> m; for (int i = 1; i <= m; ++i) { cin >> a[n + i].room >> a[n + i].f >> a[n + i].cost; } n += m; sort(a + 1, a + n + 1); fill_n(dp[0], 50 * N, -INF); fill_n(dp[1], 50 * N, -INF); dp[0][0] = 0; for (int i = 1; i <= n; ++i) { int b = i & 1; fill_n(dp[b], 50 * i, -INF); if (a[i].cost < 0) { for (int j = 0; j <= 50 * i; ++j) { if (j + a[i].room <= 50 * i) dp[b][j + a[i].room] = max(dp[b ^ 1][j] + a[i].cost, dp[b][j + a[i].room]); dp[b][j] = max(dp[b][j], dp[b ^ 1][j]); } } else { for (int j = 0; j <= 50 * i; ++j) { dp[b][j] = max(dp[b ^ 1][j], dp[b][j]); if (j >= a[i].room) { dp[b][j - a[i].room] = max(dp[b][j - a[i].room], dp[b ^ 1][j] + a[i].cost); } } } } ll ans = 0; for (int i = 0; i <= 50 * n; ++i) { ans = max(ans, dp[n & 1][i]); } cout << ans << "\n"; return 0; }

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen(tst".INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen(tst".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...