new file: 24.cpp
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
int T, n, m;
|
||||
long long k;
|
||||
int p[500005], t[500005], lg2[500005];
|
||||
template <typename TT>
|
||||
inline TT read()
|
||||
{
|
||||
TT x = 0;
|
||||
bool w = true;
|
||||
register char ch = getchar();
|
||||
while (ch < '0' || ch > '9')
|
||||
{
|
||||
if (ch == '-')
|
||||
w = false;
|
||||
ch = getchar();
|
||||
}
|
||||
while (ch >= '0' && ch <= '9')
|
||||
x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar();
|
||||
return w ? x : -x;
|
||||
}
|
||||
template <typename TT>
|
||||
inline void put(TT x)
|
||||
{
|
||||
if (x < 0)
|
||||
putchar('-'), x = -x;
|
||||
if (x > 9)
|
||||
put(x / 10);
|
||||
putchar(x % 10 + '0');
|
||||
}
|
||||
|
||||
inline bool pd(const int &L, const int &R)
|
||||
{
|
||||
if (R > n)
|
||||
return false;
|
||||
for (register int i = L; i <= R; i++)
|
||||
t[i] = p[i];
|
||||
long long sum = 0;
|
||||
sort(t + L, t + R + 1);
|
||||
int l = L, r = R, cnt = 0;
|
||||
while (l < r && sum <= k && ++cnt <= m)
|
||||
sum += (long long)(t[r] - t[l]) * (t[r] - t[l]), l++, r--;
|
||||
return sum <= k;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
for (register int i = 2; i <= 5e5; i++)
|
||||
lg2[i] = lg2[i >> 1] + 1;
|
||||
T = read<int>();
|
||||
while (T--)
|
||||
{
|
||||
n = read<int>(), m = read<int>(), k = read<long long>();
|
||||
for (register int i = 1; i <= n; i++)
|
||||
p[i] = read<int>();
|
||||
int ans = 0;
|
||||
int l = 1, r = l, flag = 1;
|
||||
while (r <= n)
|
||||
{
|
||||
if (!flag)
|
||||
ans++, l = r + 1, r = l;
|
||||
if (pd(l, r + (1 << flag) - 1))
|
||||
r = r + (1 << flag) - 1, flag++;
|
||||
else
|
||||
flag--;
|
||||
}
|
||||
put(ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user