This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 3e5+5;
int n, D;
int ans, crr;
pair<int, pii> fuel[maxn];
int sB[maxn];
int main(){
cin >> n >> D;
fuel[0].f = 0;
for(int i = 1; i <= n; i++){
cin >> fuel[i].f >> fuel[i].s.f >> fuel[i].s.s;
sB[i] = fuel[i].s.s;
}
sort(sB+1, sB+n+1);
sort(fuel+1, fuel+n+1);
for(int i = 1; i <= n; i++){
int crr = 0, ff = 0, gg = 1;
for(int j = 1; j <= n; j++){
crr-=fuel[j].f-fuel[j-1].f;
if(crr < 0){
ff-=crr;
crr = 0;
}
if(fuel[j].s.s >= sB[i])crr+=fuel[j].s.f;
if(ff > sB[i]){
gg = 0;
break;
}
}
crr -= D-fuel[n].f;
if(crr < 0){
ff-=crr;
crr = 0;
}
if(ff > sB[i])gg=0;
if(gg){
cout << ff;
return 0;
}
}
cout << D;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |