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/extc++.h>
#define int long long
using namespace std;
using namespace __gnu_pbds;
int const mxN = 3e5+5;
pair<int,pair<int,int>> a[mxN];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int n,d; cin>>n>>d;
for(int i=0; i<n; i++) cin>>a[i].first>>a[i].second.first>>a[i].second.second;
a[n].first = d;
sort(a,a+n+1);
if(n!=1) {
int l = 0, r = 1e9, ans = 0;
while(l<=r) {
int mid = (l+r) / 2;
bool f = 1;
int now = mid;
if(mid<a[0].first) f = 0;
else now -= a[0].first;
for(int i=0; i<n; i++) {
if(mid<=a[i].second.second) now += a[i].second.first;
if(now<abs(a[i+1].first-a[i].first)) { f = 0; break; }
}
if(f) { r = mid-1; ans = mid;}
else l = mid+1;
}
cout<<ans;
}
else {
for(int i=1; i<=d; i++) {
int mid = i, now = i;
bool f = 1;
if(mid<a[0].first) f = 0;
else now -= a[0].first;
for(int j=0; j<n; j++) {
if(mid<=a[j].second.second) now += a[j].second.first;
if(now<abs(a[j+1].first-a[j].first)) { f = 0; break; }
}
if(f) { cout<<mid<<'\n'; return 0; }
}
}
return 0;
}
# | 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... |