题意:相当难读的题,政府有n块场地,示威者要申请m天的场地进行示威,场地是m块不同的,政府有k 元,每当示威者进行一次申请,政府可以付出对应的费用拒绝,至少要保证把最坏的 (也就是第n块场地)给示威者,场地好坏从1-n递减,问示威者最好能得到哪块场地
直接贪心就行,先判断钱能否拒绝所有的场地,具体看代码
#include <iostream>
#include <map>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define rep(i, j, k) for(ll i = j; i <= k; i++)
#define ll long long
#define maxn 1000009
#define inf 0x7fffffff
using namespace std;
int n, m;
ll tot, a[maxn], b[maxn];
bool cmp (ll x, ll y)
{
return x > y;
}
int main ()
{
cin >> n >> m >> tot;
if (m == n)
{
cout << n << endl;
return 0;
}
rep (i, 1, n)
cin >> a[i];
rep (i, 1, n - 1)
b[i] = a[i];
sort (b + 1, b + n, cmp);
ll num = 0;
rep (i, 1, m - 1)
num += b[i];
rep (i, 1, n)
if (a[i] >= b[m])
{
if (num + b[m] > tot)
{
cout << i << endl;
return 0;
}
}
else
if (num + a[i] > tot)
{
cout << i << endl;
return 0;
}
cout << n << endl;
return 0;
}