这题可以 n 方草过(
查看原帖
这题可以 n 方草过(
431289
lalaouye楼主2024/7/15 09:30
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; ++ i)
#define rrp(i, l, r) for (int i = r; i >= l; -- i)
#define eb emplace_back
#define inf 1000000000
#define linf 100000000000000
#define pii pair <int, int>
#define ls (p << 1)
#define rs (ls | 1)
using namespace std;
constexpr int N = 1e5 + 5, P = 1e9 + 7;
const double eps = 1e-5;
inline int rd ()
{
	int x = 0, f = 1;
	char ch = getchar ();
	while (! isdigit (ch)) { if (ch == '-') f = -1; ch = getchar (); }
	while (isdigit (ch)) { x = (x << 1) + (x << 3) + ch - 48; ch = getchar (); }
	return x * f;
}
class node
{
  public:
    int l, s, v;
  friend bool operator < (const node &a, const node &b)
  {
    return a.l != b.l ? a.l < b.l : a.s < b.s;
  }
} a[N];
int n, f[N];
bool ok[N];
int main ()
{
  n = rd ();
  rep (i, 1, n) a[i].l = rd (), a[i].s = n - rd () - a[i].l;
  sort (a + 1, a + n + 1);
  int cnt = 0;
  rep (i, 1, n)
  {
    ++ cnt;
    if (a[i].l != a[i + 1].l || a[i].s != a[i + 1].s)
    {
      ok[i] = 1;
      a[i].v = min (a[i].s, cnt);
      cnt = 0;
    }
  }
  memset (f, -127, sizeof f); f[0] = 0;
  int ans = 0;
  rep (i, 1, n)
  {
    if (ok[i])
    {
      rep (j, 0, a[i].l) f[a[i].l + a[i].s] = max (f[a[i].l + a[i].s], f[j] + a[i].v);
    }
  }
  rep (i, 1, n) ans = max (ans, f[i]);
  printf ("%d\n", n - ans);
}
/*
10
2 6
2 6
2 8
1 8
3 5
3 4
6 0
0 7
1 3
2 6
*/
2024/7/15 09:30
加载中...