이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> dpl;
map<long long, long long, greater<long long> > dpr;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, ans=1e18;
cin >> n >> m;
dpl[1]=dpr[m]=0;
dpl[m]=dpr[1]=1e18;
for (long long i=1; i<=n; i++)
{
long long a, b, c, d, l, r;
cin >> a >> b >> c >> d;
l=dpl.lower_bound(a)->second;
r=dpr.lower_bound(b)->second;
ans=min(ans, l+r+d);
auto it=dpl.insert({c, l+d}).first;
long long k=min(it->second, l+d);
it->second=k;
if (next(it)!=dpl.end() && next(it)->second<=k)
it=dpl.erase(it);
while (it!=dpl.begin() && (--it)->second>=k)
it=dpl.erase(it);
it=dpr.insert({c, r+d}).first;
k=min(it->second, r+d);
it->second=k;
if (next(it)!=dpr.end() && next(it)->second<=k)
it=dpr.erase(it);
while (it!=dpr.begin() && (--it)->second>=k)
it=dpr.erase(it);
}
if (ans<=1e17)
cout << ans;
else
cout << -1;
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... |