이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int MAXN = 2228;
const int MAXC = 50 * MAXN;
const ll inf = 1e18;
int n, m;
struct kek {
int x;
int y;
int z;
bool operator < (kek a) {
return y < a.y;
}
};
kek a[MAXN], b[MAXN];
ll dp[2][MAXC];
void addComputer(int ind) {
dp[0][MAXC - 1] = -inf;
for (int i = MAXC - 2; i >= 0; i--) {
ll mx = dp[0][i + 1];
chkmax(mx, dp[1][i]);
chkmax(mx, dp[1][max(0, i - a[ind].x)] - a[ind].z);
dp[0][i] = mx;
}
swap(dp[0], dp[1]);
}
void addCustomer(int ind) {
dp[0][MAXC - 1] = -inf;
for (int i = MAXC - 2; i >= 0; i--) {
ll mx = dp[0][i + 1];
chkmax(mx, dp[1][i]);
if (i + b[ind].x < MAXC) {
chkmax(mx, dp[1][i + b[ind].x] + b[ind].z);
}
dp[0][i] = mx;
}
swap(dp[0], dp[1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//read(FILENAME);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y >> a[i].z;
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> b[i].x >> b[i].y >> b[i].z;
}
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
for (int i = 1; i < MAXC; i++) {
dp[1][i] = -inf;
}
int j = n + 1;
for (int i = m; i >= 1; i--) {
while (j > 1 && a[j - 1].y >= b[i].y) {
j--;
addComputer(j);
}
addCustomer(i);
}
cout << dp[1][0] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |