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(n+1);
vector<array<int , 3>> u(n);
int arr[n+1] = {};
// arr[i] = cost to go from i to i+1
for (int i= 1 ; i <= n ; i++){
for (int j = 0 ; j < 3 ; j++){
cin >> v[i][j];
}
}
v.push_back({d , 0 , 0});
sort(v.begin() , v.end());
for (int i = 1 ; i <= n ; i++){
u[i-1] = {v[i][2] , v[i][1] , i};
}
u.push_back({(int)1e18 , 0 , 0});
sort(u.begin() , u.end() , greater<>());
for (int i = 0 ; i <= n ; i++){
arr[i] = v[i+1][0] - v[i][0];
}
int ans = 1e18;
int id = 0;
for (int i = 0 ; i <= n ; i++){
while (id <= n && u[id][0] >= u[i][0]) { arr[u[id][2]]-=u[id][1]; id++;}
int mx = 0 , sum = 0;
for (int j = 0 ; j <= n ; j++) {
//cout << arr[j] << ' ' ;
sum += arr[j];
mx = max(mx , sum);
}
// cout << mx << ' ' << u[i][0] << '\n';
// cout << '\n';
if (mx <= u[i][0]) ans = min(ans , mx);
}
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... |