#include <bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
using pii = pair<int, int>;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> a){
return o << '(' << a.F << ',' << a.S << ')';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
map<int, ll> dp;
vector<pair<int, pii>> ev;
for(int i = 1; i <= m; i++){
int l, r, c, t;
cin >> t >> l >> r >> c;
assert(t == 1);
ev.eb(mp(l, mp(r, c)));
}
//cerr << "ok\n";
lsort(ev);
dp[0] = 0;
for(auto i : ev){
int l = i.F;
int r = i.S.F;
ll c = i.S.S;
while(!dp.empty() && dp.begin()->F < l - 1) dp.erase(dp.begin());
if(dp.empty()) break;
//cerr << "test " << l << " " << r << " " << c << "\n";
//printv(dp, cerr);
c += dp.begin()->S;
if(dp.find(r) == dp.end()) dp[r] = c;
else dp[r] = min(dp[r], c);
auto it = dp.lower_bound(r);
while(it != dp.begin() && prev(it)->S >= c){
it = dp.erase(prev(it));
}
if(next(it) != dp.end() && next(it)->S <= c) dp.erase(it);
//cerr << "test " << l << " " << r << " " << c << "\n";
//printv(dp, cerr);
}
if(dp.empty() || dp.rbegin()->F != n){
cout << "-1\n";
return 0;
}
cout << dp.rbegin()->S << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1996 KB |
Output is correct |
2 |
Correct |
45 ms |
2500 KB |
Output is correct |
3 |
Correct |
76 ms |
3632 KB |
Output is correct |
4 |
Correct |
79 ms |
3608 KB |
Output is correct |
5 |
Correct |
48 ms |
2472 KB |
Output is correct |
6 |
Correct |
45 ms |
2520 KB |
Output is correct |
7 |
Correct |
46 ms |
2480 KB |
Output is correct |
8 |
Correct |
44 ms |
2468 KB |
Output is correct |
9 |
Correct |
46 ms |
2460 KB |
Output is correct |
10 |
Correct |
60 ms |
2524 KB |
Output is correct |
11 |
Correct |
48 ms |
2496 KB |
Output is correct |
12 |
Correct |
58 ms |
2484 KB |
Output is correct |
13 |
Correct |
48 ms |
2488 KB |
Output is correct |
14 |
Correct |
52 ms |
2496 KB |
Output is correct |
15 |
Correct |
56 ms |
2564 KB |
Output is correct |
16 |
Correct |
57 ms |
2500 KB |
Output is correct |
17 |
Correct |
45 ms |
2464 KB |
Output is correct |
18 |
Correct |
44 ms |
2500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1996 KB |
Output is correct |
2 |
Correct |
45 ms |
2500 KB |
Output is correct |
3 |
Correct |
76 ms |
3632 KB |
Output is correct |
4 |
Correct |
79 ms |
3608 KB |
Output is correct |
5 |
Correct |
48 ms |
2472 KB |
Output is correct |
6 |
Correct |
45 ms |
2520 KB |
Output is correct |
7 |
Correct |
46 ms |
2480 KB |
Output is correct |
8 |
Correct |
44 ms |
2468 KB |
Output is correct |
9 |
Correct |
46 ms |
2460 KB |
Output is correct |
10 |
Correct |
60 ms |
2524 KB |
Output is correct |
11 |
Correct |
48 ms |
2496 KB |
Output is correct |
12 |
Correct |
58 ms |
2484 KB |
Output is correct |
13 |
Correct |
48 ms |
2488 KB |
Output is correct |
14 |
Correct |
52 ms |
2496 KB |
Output is correct |
15 |
Correct |
56 ms |
2564 KB |
Output is correct |
16 |
Correct |
57 ms |
2500 KB |
Output is correct |
17 |
Correct |
45 ms |
2464 KB |
Output is correct |
18 |
Correct |
44 ms |
2500 KB |
Output is correct |
19 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
20 |
Halted |
0 ms |
0 KB |
- |