1 solutions
-
1
#include <cstring> #include <algorithm> using namespace std; struct ss { int n; int v; int m; } a[1001]; #define M 1000000 int f[M]; int t, n, k, ans; int w[M], c[M]; int main() { scanf("%d", &t); while(t--) { memset(f, 0, sizeof(f)); ans = 0; scanf("%d%d", &n, &k); for(int i = 1; i <= n; i++) scanf("%d", &w[i]); for(int i = 1; i <= n; i++) scanf("%d", &c[i]), f[i] = c[i]; for(int i = 1; i <= n; i++) { for(int j = 1; j <= i; j++) { if(w[i] - w[j] > k) f[i] = max(f[i], f[j] + c[i]); ans = max(f[i], ans); } } printf("%d\n", ans); } return 0; }
- 1
Information
- ID
- 781
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- # Submissions
- 16
- Accepted
- 6
- Uploaded By