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 int long long
void doWork(){
int N , D;
cin >> N >> D;
vector<array<int, 3>> v;
vector<array<int , 3>> B;
for (int i = 0 ; i < N ; i++){
int x , a , b ;
cin >> x >> a >> b;
v.push_back({x , a , b});
}
v.push_back({D , 0 , 0});
sort(v.begin() , v.end());
for (int i = 0 ; i < N ; i++){
B.push_back({v[i][2], v[i][1] , i});
}
sort(B.begin() , B.end());
int x[N+1] = {};
for (int i = 0 ; i <= N ; i++){
x[i] = - v[i][0];
}
int ans = 1e18;
int id = 0;
for (int F = 0 ; F < N ; F++){
while(id <= N && B[id][0] <= B[F][0]) { for (int j = B[id][2] + 1 ; j <= N ; j++) x[j] += B[id][1]; id++; }
int mn = 0;
for (int j = 0 ; j <= N ; j++) {mn = min(mn , x[j]); }
if (-mn <= B[F][0]) ans = min(ans , -mn);
}
cout << ans;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
doWork();
}
# | 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... |