求调85pts
查看原帖
求调85pts
1401678
haley001楼主2025/6/21 20:45
#include<bits/stdc++.h>
#define int long long
#define endl <<'\n';
#define kz <<' '<<
#define km <<' ';
#define kh <<' ' endl
#define out cout<<
#define map unordered_map
#define set unordered_set
#define F(x,a,b,c) for(int x = (a); x <= (b); x+=(c))
#define FF(x,a,b,c) for(int x = (a); x >= (b); x-=(c))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define pbk push_back
#define creak continue;
#define break break;
#define sit short
#define ud using namespace std;
#define qwq return
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define main signed main()
#define W while
ud
static char buf[100000], * pa(buf), * pb(buf);
#define gc pa == pb && (pb = (pa = buf) + fread(buf, 1, 100000, stdin), pa == pb) ? EOF : *pa++
void read(int &x) {
	x = 0;
	int f = 1;
	char ch = gc;
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = gc;
	}
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - 48, ch = gc;
	x *= f;
}
template <typename T, typename ...Args> void read(T &nums, Args &...args) {
	read(nums);
	read(args...);
}
void write(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
	return;
}
void wtem(int x) {
	write(x), putchar('\n');
}
void wte(int x, char c = ' ') {
	write(x), putchar(c);
}
int n, m, k, nowk, ox;
pair<int, int>a[500100];
bool cmp(pair<int, int>a, pair<int, int>b) {
	if (a.first == b.first)return a.second < b.second;
	else return a.first > b.first;
}
main{
	ios
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
		if (a[i].second == k) {
			nowk = i;
			break;
		}
	}
	for (int i = nowk - 1; i >= 1; i--) {
		if (a[i].first == a[1].first)break;
		if (a[i].second < a[nowk].second && m >= a[i].first - a[nowk].first + 1)m -= a[i].first - a[nowk].first + 1, ox++;
		else if (m >= a[i].first - a[nowk].first)m -= a[i].first - a[nowk].first, ox++;
	}
	cout << nowk - ox;
	qwq 0;
}

2025/6/21 20:45
加载中...