LCS on Permutations

Problem Info

LCS on Permutations

My Work

// template stuff not included
int main() {
	setIO();
	int n;
	cin >> n;
	vector<pii> nums(n);
	for (int i = 0; i < n; i++) {
		cin >> nums[i].first;
	}
	for (int i = 0; i < n; i++) {
		cin >> nums[i].second;
	}
	sort(nums.begin(), nums.end());
	vector<int> dp;
	for (int i = 0; i < n; i++) {
		int pos = upper_bound(dp.begin(), dp.end(), nums[i].second) - dp.begin();
		if (pos == dp.size()) {
			dp.push_back(nums[i].second);
		} else {
			dp[pos] = nums[i].second;
		}
	}
	cout << dp.size() << endl;
	return 0;
}

Question

This code gets WA on test case 2, but shouldn’t it be equivalent to the solution (https://usaco.guide/problems/cf-lis-on-permutations/solution)?