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<int> B(1 , 1e18);
for (int i = 1 ; i <= n ; i++){
int x , a , b;
cin >> x >> a >> b;
v.push_back({x , b , -a});
B.push_back(b);
}
sort(v.begin() , v.end());
sort(B.begin() , B.end());
int x[n+1] = {} , a[n+1] = {} , b[n+1] = {};
for (int i = 1 ; i <= n ; i++){
x[i] = v[i-1][0];
a[i] = v[i-1][2];
b[i] = v[i-1][1];
}
int ans = 1e18;
for (int i = 0 ; i <= n ; i++){
// cout << B[i] << '\n' << '\n';
int mn = 0 , sum = 0;
for (int j = 1 ; j <= n ; j++){
// cout << mn << ' ' << sum << '\n';
mn = min(mn , -x[j] + sum);
if (b[j] <= B[i]) sum -= a[j];
}
//cout << '\n';
if (-mn <= B[i]) 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... |