1 solutions
-
0
C++ :
#include<bits/stdc++.h> using namespace std; #define ll long long ll n, d, k; ll dp[500005]; struct gezi { ll pos; ll zhi; }a[500005]; bool check(int m) { ll maxx = d + m; ll minn = d - m; if (minn <= 0)minn = 1; memset(dp, -128, sizeof(dp)); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = i - 1; j >= 0; j--) { if (a[i].pos - a[j].pos < minn)continue; if (a[i].pos - a[j].pos > maxx)break; dp[i] = max(dp[i], dp[j] + a[i].zhi); if (dp[i] >= k) { return 1; } } } return 0; } int main() { cin >> n >> d >> k; int sum = 0; int ans = -1; a[0].pos = 0; a[0].zhi = 0; for (int i = 1; i <= n; i++) { cin >> a[i].pos >> a[i].zhi; if (a[i].zhi > 0) { sum += a[i].zhi; } } int l = 0, r = 1005; int mid; while (l < r) { mid = (l + r) / 2; if (check(mid)) { r = mid; ans = r; } else { l = mid + 1; } } cout << ans << endl; }
- 1
Information
- ID
- 9204
- Time
- 2000ms
- Memory
- 256MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By