如何理解这个题目呢,我们可以每个人的分数放到排名上,然后求解最长下降序列即可
#include<bits/stdc++.h>
using namespace std;int n;
const int N = (int)1e5 + 5;
int a[N];
int b[N];
int d[N];
int dp[N];
int t;int main() {cin >> t;while (t--) {cin >> n;for (int i = 1; i <= n; i++) {int c, d;cin >> c >> d;a[i] = c - d;}for (int i = 1; i <= n; i++) {cin >> b[i];d[i] = a[b[i]];}int ans = 0;memset(dp, 0, sizeof dp);dp[1] = 1;for (int i = 2; i <= n; i++) {for (int j = 1; j < i; j++) {if (d[i] <= d[j]) {dp[i] = max(dp[i], dp[j] + 1);}else dp[i] = 1;}}cout << n-dp[n];}return 0;
}