Submission #374194

#TimeUsernameProblemLanguageResultExecution timeMemory
374194Mamnoon_SiamTwo Dishes (JOI19_dishes)C++17
0 / 100
4 ms1132 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; #define all(v) begin(v), end(v) #define sz(v) (int)(v).size() #define fi first #define se second string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif const int N = 2e3 + 3; const ll inf = 1e18; int n, m; ll A[N], B[N], S[N], T[N], P[N], Q[N]; vector<pair<int, ll>> donburi[N], curry[N]; ll dp[N]; void chkmax(ll& x, ll y) { x = max(x, y); } void CHKMAX(int l, int r, ll x) { for(int i = l; i <= r; ++i) chkmax(dp[i], x); } void range_add(int l, int r, ll x) { for(int i = l; i <= r; ++i) dp[i] += x; } ll range_max(int l, int r) { ll ret = LLONG_MIN; for(int i = l; i <= r; ++i) chkmax(ret, dp[i]); return ret; } int main(int argc, char const *argv[]) { #ifdef LOCAL freopen("in", "r", stdin); #endif scanf("%d %d", &n, &m); for(int i = 1; i <= n; ++i) { scanf("%lld %lld %lld", &A[i], &S[i], &P[i]); A[i] += A[i-1]; } for(int i = 1; i <= m; ++i) { scanf("%lld %lld %lld", &B[i], &T[i], &Q[i]); B[i] += B[i-1]; } for(int i = 1; i <= n; ++i) { if(S[i] < A[i]) continue; int j = int(upper_bound(B, B+m+1, S[i] - A[i]) - B - 1); donburi[i].emplace_back(j, P[i]); } for(int i = 1; i <= m; ++i) { if(T[i] < B[i]) continue; int j = int(upper_bound(A, A+n+1, T[i] - B[i]) - A - 1); curry[j].emplace_back(i, Q[i]); } fill(dp+1, dp+1+m, -inf); for(int x = 0; x <= n; ++x) { for(auto [r, val] : donburi[x]) { range_add(0, r, val); } for(auto [l, val] : curry[x]) { range_add(l, m, val); } sort(all(curry[x])); for(auto [y, val] : curry[x]) { ll ex = range_max(0, y-1); CHKMAX(y, m, val + ex); } } printf("%lld\n", dp[m]); return 0; } /* * use std::array instead of std::vector, if u can * overflow? * array bounds */

Compilation message (stderr)

dishes.cpp: In function 'int main(int, const char**)':
dishes.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   90 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
dishes.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   92 |     scanf("%lld %lld %lld", &A[i], &S[i], &P[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   96 |     scanf("%lld %lld %lld", &B[i], &T[i], &Q[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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...