Submission #768976

#TimeUsernameProblemLanguageResultExecution timeMemory
768976nguyentunglamTwo Dishes (JOI19_dishes)C++17
10 / 100
8 ms892 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 2010; long long a[N], b[N], s[N], t[N], p[N], q[N]; long long f[N]; vector<int> event[N]; int n, m; void up(int j, int x) { long long sum = 0; for(int i = j; i >= 1; i--) { if (x <= t[i]) sum += q[i]; f[j] = max(f[j], f[i - 1] + sum); } } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } cin >> n >> m; for(int i = 1; i <= n; i++) { cin >> a[i] >> s[i] >> p[i]; p[i] = max(0LL, p[i]); a[i] += a[i - 1]; } for(int i = 1; i <= m; i++) { cin >> b[i] >> t[i] >> q[i]; q[i] = max(0LL, q[i]); b[i] += b[i - 1]; } for(int i = 1; i <= n; i++) { int l = 0, r = m, last = -1; while (l <= r) { int mid = l + r >> 1; if (a[i] + b[mid] <= s[i]) { last = mid; l = mid + 1; } else r = mid - 1; } s[i] = last; } for(int i = 1; i <= m; i++) { int l = 0, r = n, last = -1; while (l <= r) { int mid = l + r >> 1; if (b[i] + a[mid] <= t[i]) { last = mid; l = mid + 1; } else r = mid - 1; } t[i] = last; if (last >= 0) event[last].push_back(i); } for(int i = 1; i <= m; i++) f[i] = -1e18; for(int i = 1; i <= n; i++) { for(int &j : event[i - 1]) up(j, i - 1); for(int j = 0; j <= s[i]; j++) f[j] += p[i]; // for(int j = 0; j <= m; j++) cout << f[j] << " "; } up(m, n); cout << f[m]; }

Compilation message (stderr)

dishes.cpp: In function 'int main()':
dishes.cpp:46:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |             int mid = l + r >> 1;
      |                       ~~^~~
dishes.cpp:58:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |             int mid = l + r >> 1;
      |                       ~~^~~
dishes.cpp:25:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:26:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:29:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:30:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...