Submission #259189

#TimeUsernameProblemLanguageResultExecution timeMemory
259189patrikpavic2Two Dishes (JOI19_dishes)C++17
74 / 100
2824 ms172944 KiB
#include <cstdio> #include <cstring> #include <vector> #include <set> #include <algorithm> #define PB push_back using namespace std; typedef long long ll; const int N = 1e6 + 500; const ll INF = 1e18; ll del[N], mora[N], S[N], T[N]; int n, m; int Q[N], P[N], A[N], B[N]; int SS[N], TT[N]; vector < ll > v, v2; vector < int > brisi[N]; set < int > raz; void pocisti(int sad){ if(del[sad] > mora[sad]){ raz.insert(sad); return; } if(del[sad] == mora[sad] && raz.count(sad)) raz.erase(sad); if(del[sad] >= mora[sad]) return; ll trb = mora[sad] - del[sad]; del[sad] = mora[sad]; sad++; while(sad <= m && trb > 0){ if(del[sad] - mora[sad] > trb){ del[sad] -= trb; break; } trb -= (del[sad] - mora[sad]); del[sad] = mora[sad]; raz.erase(sad); if(raz.lower_bound(sad) == raz.end()) break; sad = *(raz.upper_bound(sad)); } } int main(){ scanf("%d%d", &n, &m); for(int i = 1;i <= n;i++) scanf("%d%lld%d", A + i, S + i, P + i); for(int i = 1;i <= m;i++) scanf("%d%lld%d", B + i, T + i, Q + i); ll cur = 0; v.PB(cur); for(int i = 1;i <= m;i++) cur += B[i], v.PB(cur); cur = 0; v2.PB(cur); for(int i = 1;i <= n;i++){ cur += A[i]; v2.PB(cur); if(S[i] < cur) P[i] = 0, S[i] = cur; SS[i] = upper_bound(v.begin(), v.end(), S[i] - cur) - v.begin() - 1; } cur = 0; for(int i = 1;i <= m;i++){ cur += B[i]; if(T[i] < cur) Q[i] = 0, T[i] = cur; TT[i] = upper_bound(v2.begin(), v2.end(), T[i] - cur) - v2.begin() - 1; } for(int i = m;i >= 1;i--){ del[i] = Q[i], mora[i] = Q[i]; if(TT[i]){ brisi[TT[i]].PB(i); } else{ mora[i] = 0; pocisti(i); } } for(int i = 1;i <= n;i++){ del[0] += P[i]; del[SS[i] + 1] -= P[i]; pocisti(SS[i] + 1); if(i == n) break; for(int j : brisi[i]){ mora[j] = 0; pocisti(j); } } ll ans = 0; for(int i = 0;i <= m;i++) ans += del[i]; printf("%lld\n", ans); }

Compilation message (stderr)

dishes.cpp: In function 'int main()':
dishes.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%d", A + i, S + i, P + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%d", 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...