제출 #1171065

#제출 시각아이디문제언어결과실행 시간메모리
1171065bbartekTwo Dishes (JOI19_dishes)C++20
5 / 100
75 ms9800 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define st first #define nd second #define pb push_back const int maxn = 1e6+7; ll czas1[maxn]; ll czas2[maxn]; ll prog1[maxn]; ll prog2[maxn]; ll nagroda1[maxn]; ll nagroda2[maxn]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin>>n>>m; ll a,b,c; for(int i=1;i<=n;i++){ cin>>a>>b>>c; czas1[i] = a; prog1[i] = b; nagroda1[i] = c; } for(int i=1;i<=m;i++){ cin>>a>>b>>c; czas2[i] = a; prog2[i] = b; nagroda2[i] = c; } ll licz=0; ll wyn = 0; ll maks = -1e18; ll kon = n; for(int i=1;i<=n;i++){ if(licz + czas1[i] > prog1[1]){ kon = i-1; break; } licz += czas1[i]; wyn += nagroda1[i]; } int x=1; while(x<=m && licz + czas2[x] <= prog1[1]){ wyn += nagroda2[x]; licz += czas2[x]; x++; } maks = max(maks,wyn); for(int i=kon;i>=1;i--){ licz -= czas1[i]; wyn -= nagroda1[i]; while(x<=m && licz + czas2[x] <= prog1[1]){ wyn += nagroda2[x]; licz += czas2[x]; x++; } maks = max(maks,wyn); } cout<<maks<<"\n"; return 0; }
#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...