#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Pk {
int a, b, t;
bool operator<(const Pk other) const {
return a < other.a;
}
};
int n, k, m, sz1, sz2, dp[105][2005];
Pk v1[105],v2[105];
int f(int idx, int T) {
if(idx>=sz1) return 0;
if(~dp[idx][T]) return dp[idx][T];
ll ret=0;
if(T<v1[idx].t) ret+=v1[idx].b;
if(idx!=sz1-1) {
ret+=f(idx+1,T+v1[idx+1].a-v1[idx].a);
}
return dp[idx][T]=ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(dp,-1,sizeof dp);
cin >> n >> k >> m;
ll ans=0;
for(int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
if(a==k) {
ans += b;
continue;
}
if(a>k) v1[sz1++]={a,b,t};
else v2[sz2++]={a,b,t};
}
sort(v1, v1+sz1);
sort(v2, v2+sz2);
reverse(v2, v2+sz2);
ans = f(0,v1[0].a-k);
ll sum = 0;
for(int i = 0; i < sz2; i++) {
if(v2[i].t > k - v2[i].a) {
sum += v2[i].b;
}
ans = max(ans, sum + f(0, k - v2[i].a + v1[0].a - v2[i].a));
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
1 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
1152 KB |
Output is correct |
5 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |
8 |
Correct |
1 ms |
1152 KB |
Output is correct |
9 |
Correct |
1 ms |
1152 KB |
Output is correct |
10 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |