比赛 |
20241025 |
评测结果 |
AAAAAAAAAA |
题目名称 |
品质控制 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
1.027 s |
代码语言 |
C++ |
内存使用 |
6.94 MiB |
提交时间 |
2024-10-25 11:57:10 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 5e5+10;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
ll n,m,k;
ll a[N],b[N],c[N];
ll get(int L,int mid,int R){
for(int i = mid;i < R;i++)b[i] = a[i];
sort(b+mid,b+R);
int i = L,j = mid;
for(int d = L;d < R;d++){
if(j >= R || (i < mid && b[i] <= b[j]))c[d] = b[i++];
else c[d] = b[j++];
}
ll ss = 0;
for(int i = L,j = R-1;i < L+m && i < j;i++,j--)ss += (c[j] - c[i]) * (c[j] - c[i]);
return ss;
}
int main(){
freopen("cont.in","r",stdin);
freopen("cont.out","w",stdout);
int t = read();
while(t--){
n = read(),m = read(),k = read();
for(int i = 1;i <= n;i++)a[i] = read();
int ans = 0,l = 1,r = 0,p = 0;
while(l <= n){
r = l;p = 1;
while(p){
if(r + p <= n + 1 && get(l,r,r + p) <= k){
r += p;p <<= 1;
for(int i = l;i < r;i++)b[i] = c[i];
}
else p /= 2;
}
l = r;
ans++;
}
printf("%lld\n",ans);
}
return 0;
}