#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define sz(x) int(x.size())
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
const int mx = 1'000'000;
const ll INF = 1'000'000'000'000'000'000LL;
int N, M;
vi A(1+mx), S(1+mx), P(1+mx);
vi B(1+mx), Q(1+mx), T(1+mx);
vll Asum(1+mx, 0);
vll Bsum(1+mx, 0);
struct delta
{
int p;
ll v;
};
bool operator < (delta A, delta B)
{
if(A.p == B.p) return A.v < B.v;
return A.p < B.p;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
for(int i = 1; i <= N; i++)
{
cin >> A[i] >> S[i] >> P[i];
Asum[i] = Asum[i-1] + A[i];
}
for(int j = 1; j <= M; j++)
{
cin >> B[j] >> T[j] >> Q[j];
Bsum[j] = Bsum[j-1] + B[j];
}
vvll DP(1+N, vll(1+M, -INF));
DP[0][0] = 0;
for(int i = 0; i <= N; i++)
{
for(int j = 0; j <= M; j++)
{
if(i != 0)
{
DP[i][j] = max(DP[i][j], DP[i-1][j] + (Asum[i] + Bsum[j] <= S[i] ? P[i] : 0));
}
if(j != 0)
{
DP[i][j] = max(DP[i][j], DP[i][j-1] + (Asum[i] + Bsum[j] <= T[j] ? Q[j] : 0));
}
}
}
cout << DP[N][M] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
361 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
39372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
361 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
361 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |