题解:P14040 [PAIO 2025] Exhibition
Solution
设 lower_bound)。
先不考虑第一个条件。
两维不好做,考虑先按
现在考虑加上限制。
更新时,设原来算法二分出的位置是
若
Code
#include "exhibition.h"
#include <algorithm>
#include <utility>
#include <vector>
#define MAXN 100003
#define IMX 0x3f3f3f3f
using namespace std;
int max_paintings(int N, int M, vector<int> A, vector<int> B, vector<int> S)
{
pair<int, int> a[MAXN];
int dp[MAXN], pos[MAXN];
int i, tmp;
for (i = 0; i < N; ++i)
a[i] = {B[i], A[i]};
sort(a, a + N), sort(S.begin(), S.end());
dp[0] = 0, fill(dp + 1, dp + N + 1, IMX);
pos[0] = -1;
for (i = 0; i < N; ++i)
{
tmp = (int)(upper_bound(dp + 1, dp + N + 1, a[i].second) - dp);
pos[tmp] = max(pos[tmp - 1] + 1, (int)(lower_bound(S.begin(), S.end(), a[i].second) - S.begin()));
if (pos[tmp] >= M)
continue;
dp[tmp] = a[i].second;
}
for (i = N; dp[i] == IMX; --i)
;
return i;
}