# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
86842 | jovitre | Go (COCI18_go) | C++14 | 42 ms | 43764 KiB |
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 <bits/stdc++.h>
using namespace std;
#define MAXN 1050
#define MAXSZ 2050
#define INF 999999999
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <ll> vi;
int n, k, m;
int dp[MAXN][MAXN * 10];
int casa[MAXN];
int peso[MAXN];
int t[MAXN];
int calc(int idx, int casaAtual, int tempo){
if(idx > m) return 0;
if(dp[idx][tempo] != -1) return dp[idx][tempo];
int opt1 = calc(idx + 1, casaAtual, tempo);
int opt2 = 0;
if(tempo + abs(casaAtual - casa[idx]) < t[idx]) opt2 = peso[idx] + calc(idx + 1, casa[idx], tempo + abs(casaAtual - casa[idx]));
return dp[idx][tempo] = max(opt1, opt2);
}
int main(){
scanf("%d%d%d", &n, &k, &m);
for(int i = 1; i <= m; i++) scanf("%d%d%d", casa + i, peso + i, t + i);
memset(dp, -1, sizeof(dp));
int res = calc(1, k, 0);
printf("%d\n", res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |