Submission #267067

#TimeUsernameProblemLanguageResultExecution timeMemory
267067shayan_pTreatment Project (JOI20_treatment)C++14
35 / 100
211 ms768 KiB
// And you curse yourself for things you never done

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 5010;
const ll inf = 1e18 + 10;

int L[maxn], R[maxn], T[maxn], C[maxn];
ll dp[maxn];
bool mark[maxn];

bool ok(int l1, int r1, int t1, int l2, int r2, int t2){
    return r1 - l2 + 1 >= abs(t1-t2);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    int n, m;
    cin >> n >> m;
    fill(dp, dp + m, inf);
    for(int i = 0; i < m; i++){
	cin >> T[i] >> L[i] >> R[i] >> C[i];
	if(L[i] == 1)
	    dp[i] = C[i];
    }
    for(int i = 0; i < m; i++){
	int id = -1;	
	for(int j = 0; j < m; j++){
	    if(mark[j] == 0 && (id == -1 || dp[id] > dp[j]))
		id = j;
	}
	assert(id != -1);
	mark[id] = 1;
	for(int j = 0; j < m; j++){
	    if(ok(L[id], R[id], T[id], L[j], R[j], T[j]))
		dp[j] = min(dp[j], dp[id] + C[j]);
	}
    }
    ll ans = inf;
    for(int i = 0; i < m; i++){
	if(R[i] == n)
	    ans = min(ans, dp[i]);
    }
    if(ans == inf)
	ans = -1;
    return cout << ans << endl, 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...