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;/*
<<<<It's never too late for a new beginning in your life>>>>
Today is hard
tomorrow will worse
but the day after tomorrow will be the sunshine..
HARD WORK BEATS TALENT WHEN TALENT DOESN'T WORK HARD............
Never give up */
//The most CHALISHKANCHIK
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vii;
const int N = 2e5+50, inf = 1e18;
vector<pair<pii, pair<pii, int> > > v;
vector<pair<pii, int> > k, re;
int n, m;
bool us[N];
bool ch(){
set<pii> st;
st.insert({1, n});
for(int i = 0; i < m; i++){
if(us[i])continue;
vii todel, toins;
toins.pb({re[i].ss, re[i].ss});
int l = re[i].ff.ff, r = re[i].ff.ss;
for(auto [_l, _r]:st){
if(_l <= l && r <= _r){
todel.pb({_l, _r});
if(_l!=l)toins.pb({_l, l-1});
if(_r!=r)toins.pb({r+1, _r});
}else if(_l <= l && _r <= r && l <= _r){
todel.pb({_l, _r});
if(_l!=l)toins.pb({_l, l-1});
}else if(_r >= r && _l >= l && _l <= r){
todel.pb({_l, _r});
if(_r!=r)toins.pb({r+1, _r});
}else if(l <= _l && _r <= r){
todel.pb({_l, _r});
}
}
for(auto x:todel)st.erase(st.find(x));
for(auto x:toins)st.insert(x);
}
return (st.size()==1);
}
void solve(){
cin >> m >> n;
v.resize(m);
re.resize(m);
k.resize(m);
// 2
// 2 3
// 1 1 2 1
// 1 1
for(int i = 0; i < m; i++){
cin >> v[i].ss.ff.ff >> v[i].ss.ff.ss >> v[i].ff.ss >> v[i].ff.ff;
v[i].ss.ss = i;
re[i] = {v[i].ss.ff, v[i].ff.ss};
}
int ans = 0;
sort(rall(v));
if(!ch()){
cout << "-1\n";
return;
}
for(int i = 0; i < m; i++){
us[v[i].ss.ss] = 1;
if(ch()){
}else{
us[v[i].ss.ss] = 0;
ans += v[i].ff.ff;
}
}
cout << ans << '\n';
}
main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t = 1;
//~ cin >> t;
while(t--){
solve();
}
}
Compilation message (stderr)
pinball.cpp: In function 'bool ch()':
pinball.cpp:34:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | for(auto [_l, _r]:st){
| ^
pinball.cpp: At global scope:
pinball.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
85 | main(){
| ^~~~
# | 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... |