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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nn "\n"
#define x_x ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define intt int _; cin >> _; while (_--)
#define emp push_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define ld long double
#define A first
#define B second
//#define int long long
typedef long long ll;
const ld eps = 1e-27;
// diff between decimals 0.000000001 mt19937 mt(time(nullptr));
struct in {
int a; int b; int c;
};
bool ss(in a, in b) {
return a.a<b.a;
}
int main() {
x_x
int n,d; cin>>n>>d; in ar[n]; int mn=INT_MAX;
for (auto&i:ar) cin>>i.a>>i.c>>i.b, mn=min(mn,i.b);
sort(ar, ar+n,ss);
if (n==1) {
int x=d; int y=max(ar[0].a, d-ar[0].c); if (y>ar[0].b) y=d;
cout<<min(x,y);
}
else if(mn==(1e9)) {
ll f=0, x=0; ll s=f;
for (int i=0; i<n&&ar[i].a<d; i++) {
f-=(ar[i].a-x), x=ar[i].a;
if(f<0)s+=(f*-1),f=0;
f+=ar[i].c;
}
f-=(d-x); if(f<0) s+=(f*-1);
cout<<s;
}
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... |