#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF=2e15;
const int MAXM=1e5+6;
struct device
{
ll row,a,b,c,d;
};
device d[MAXM];
int n,m;
int main()
{
cin>>m>>n;
for(int i=2;i<m+2;i++)
{
d[i].row=i;
cin>>d[i].a>>d[i].b>>d[i].c>>d[i].d;
}
ll ans=INF;
for(int mask=0;mask<(1<<m);mask++)
{
set<int>s;
for(int i=1;i<=n;i++)
{
int u=i;
for(int j=2;j<m+2;j++)
{
if(mask&(1<<(j-2)))
{
if(d[j].a<=u&&d[j].b>=u)
{
u=d[j].c;
}
}
}
s.insert(u);
}
if(s.size()>1)
{
continue;
}
ll sum=0;
for(int j=2;j<m+2;j++)
{
if(mask&(1<<(j-2)))
{
sum+=d[j].d;
}
}
if(sum<ans)ans=sum;
}
if(ans==INF)cout<<"-1\n";
else cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
204 KB |
Output is correct |
4 |
Correct |
17 ms |
324 KB |
Output is correct |
5 |
Correct |
49 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
32 ms |
332 KB |
Output is correct |
8 |
Correct |
23 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
204 KB |
Output is correct |
4 |
Correct |
17 ms |
324 KB |
Output is correct |
5 |
Correct |
49 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
32 ms |
332 KB |
Output is correct |
8 |
Correct |
23 ms |
300 KB |
Output is correct |
9 |
Execution timed out |
1091 ms |
47196 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
204 KB |
Output is correct |
4 |
Correct |
17 ms |
324 KB |
Output is correct |
5 |
Correct |
49 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
32 ms |
332 KB |
Output is correct |
8 |
Correct |
23 ms |
300 KB |
Output is correct |
9 |
Execution timed out |
1091 ms |
47196 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
7 ms |
204 KB |
Output is correct |
4 |
Correct |
17 ms |
324 KB |
Output is correct |
5 |
Correct |
49 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
32 ms |
332 KB |
Output is correct |
8 |
Correct |
23 ms |
300 KB |
Output is correct |
9 |
Execution timed out |
1091 ms |
47196 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |