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 <iostream>
using namespace std;
pair<pair<int, int>, pair<int, int>> arr[20];
bool xd[10005];
int main() {
int n, m, a, b, c, d;
cin >> n >> m;
for(int i=0; i<m; i++) {
cin >> a >> b >> c >> d;
arr[i] = {{a, b}, {c, d}};
}
long long cost;
long long res = 1000000000000000;
int dd;
for(int i=1; i<(1<<m); i++) {
for(int j=0; j<=n; j++) {
xd[j] = false;
}
cost = 0;
for(int j=0; j<m; j++) {
if(i & (1<<j)) {
cost+=arr[j].second.second;
for(int k = arr[j].first.first; k<=arr[j].first.second; k++) {
xd[k] = true;
}
xd[arr[j].second.first] = false;
}
}
dd = 0;
for(int j=1; j<=n; j++) {
if(xd[j] == false) {
dd++;
}
}
if(dd == 1) {
res = min(res, cost);
}
}
if(res != 1000000000000000) {
cout << res;
}
else {
cout << -1;
}
}
# | 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... |