90pts求助!!!
查看原帖
90pts求助!!!
1140668
___W___Z___L___PVP楼主2024/12/21 09:59
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, k, sum = 0;

struct rode {
	int x, y;
} a[100009];

bool cmp1(rode x, rode y) {
	return x.y > y.y;
}

bool cmp2(rode x, rode y) {
	return x.x > y.x;
}

signed main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= m; i++)
		cin >> a[i].x;
	for (int i = 1; i <= m; i++)
		cin >> a[i].y;
	stable_sort(a + 1, a + m + 1, cmp1);
	stable_sort(a + 1, a + m + 1, cmp2);
	for (int i = 1; i <= m; i++)
		cout << a[i].x << ' ';
	cout << '\n';
	for (int i = 1; i <= m; i++)
		cout << a[i].y << ' ';
	cout << '\n';
	int t = 0, maxx = 0;
	rode jj = {0, 0};
	for (int i = 1; i <= m; i++) {
		if (jj.y >= k && a[i].x == jj.x)
			continue;
		if (a[i].x != jj.x) {
			jj.x = a[i].x;
			if (jj.y < k && i != 1) {
				cout << "-1";
				return 0;
			}
			maxx = max(maxx, t);
			jj.y = a[i].y;
			t = 0;
		} else {
			t++;
			jj.y += a[i].y;
		}
		sum++;
	}
	if (maxx > m / 2) {
		cout << "-1";
		return 0;
	}
	cout << sum;

	return 0;
}
2024/12/21 09:59
加载中...