#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e5 + 5;
int n, m, a[N], b[N], c[N], d[N];
pii fl[N], fr[N];
vector<int> cmp;
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> m >> n;
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
cmp.pb(a[i]);
cmp.pb(b[i]);
cmp.pb(c[i]);
}
cmp.pb(1);
cmp.pb(n);
sort(cmp.begin(), cmp.end());
cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
n = cmp.size();
for (int i = 1; i <= m; i++) {
a[i] = upper_bound(cmp.begin(), cmp.end(), a[i]) - cmp.begin();
b[i] = upper_bound(cmp.begin(), cmp.end(), b[i]) - cmp.begin();
c[i] = upper_bound(cmp.begin(), cmp.end(), c[i]) - cmp.begin();
}
int res = 1e18;
for (int i = 1; i <= m; i++) {
fl[i] = {a[i], d[i]};
fr[i] = {b[i], -d[i]};
for (int j = 1; j < i; j++) {
if (a[i] <= c[j] && c[j] <= b[i]) {
pii x = fl[j];
x.S += d[i];
fl[i] = min(fl[i], x);
x = fr[j];
x.S -= d[i];
fr[i] = max(fr[i], x);
}
}
if (fl[i].F == 1 && fr[i].F == n) {
res = min(res, fl[i].S - fr[i].S - d[i]);
}
}
if (res == 1e18) cout << -1;
else cout << res;
}
Compilation message (stderr)
pinball.cpp: In function 'int main()':
pinball.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen("INP.INP" ,"r" , stdin) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pinball.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen("OUT.OUT" , "w" , stdout) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |