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 <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int Nmax=300000;
int n, d;
struct station{
int x, a, b;
}v[Nmax+1];
priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
bool cmp(station a, station b){
return a.x<b.x;
}
int main()
{
cin>>n>>d;
for (int i=0; i<n; i++)
cin>>v[i].x>>v[i].a>>v[i].b;
sort(v, v+n, cmp);
v[n].x=d; v[n].b=d+1;
int fs=0, fadd=0;
for (int i=0; i<=n; i++){
while (v[i].x>fs+fadd && fs<=v[i].b){
fs=v[i].x-fadd;
while (!q.empty() && q.top().first<fs){
fadd-=q.top().second;
q.pop();
}
}
if (fs<=v[i].b){
fadd+=v[i].a;
q.push({v[i].b, v[i].a});
}
}
cout<<fs;
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... |