#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false);cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define x first
#define y second
const int N=150005;
const int INF=1e18;
struct st{
int t,l,r,c;
bool operator<(st &o){
return this->l<o.l;
}
};
int32_t main() {
int m,n;cin>>m>>n;
vector<st> v(n);
for(int i=0;i<n;i++){
int a,b,c,d;cin>>a>>b>>c>>d;
v[i]={a,b,c,d};
}
sort(all(v));
vector<int> dp(n);
for(int i=0;i<n;i++){
auto [t,l,r,c]=v[i];
int ans=(l==1?c:INF);
for(int j=0;j<i;j++){
auto [t1,l1,r1,c1]=v[j];
if(abs(t-t1)<=r1-l+1){
ans=min(ans,dp[j]+c);
}
}
dp[i]=ans;
}
int ans=INF;
for(int i=0;i<n;i++){
if(v[i].r==m){
ans=min(ans,dp[i]);
}
}
cout<<(ans==INF?-1:ans)<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3044 ms |
7504 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3044 ms |
7504 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |