#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int m, n;
cin>> m >> n;
int fall[n+1];
pair<pair<int, int>, pair<int, int>> arr[m];
for(int i = 0; i < m;i ++) {
cin >> arr[i].first.first >> arr[i].first.second >> arr[i].second.first >> arr[i].second.second;
}
queue<vector<bool>> q;
q.push({});
for(int i = 0; i< m; i++) {
int sz = q.size();
for(int j = 0; j < sz; j++) {
vector<bool> a = q.front();
a.push_back(true);
q.push(a);
a.pop_back();
a.push_back(false);
q.push(a);
q.pop();
}
}
int minval = LONG_LONG_MAX;
while(!q.empty()) {
for(int i = 1; i <= n; i++) fall[i] = i;
vector<bool> vec = q.front();
q.pop();
int total = 0;
for(int i = 0; i < m; i++) {
if(vec[i]) {
total += arr[i].second.second;
for(int j = 1; j <= n; j++) {
if(fall[j] >= arr[i].first.first && fall[j] <= arr[i].first.second) {
fall[j] = arr[i].second.first;
}
}
}
}
set<int> s;
for(int i = 1; i <= n; i++) {
s.insert(fall[i]);
}
if(s.size() == 1) {
minval = min(minval, total);
}
}
cout<<minval<<'\n';
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... |