求hack数据(已AC)
查看原帖
求hack数据(已AC)
235901
Always_Remember_It楼主2022/8/12 12:03
#include <bits/stdc++.h>
using namespace std;
#define fo(a,b,c) for(int a=b;a<=c;a++)
#define of(a,b,c) for(int a=b;a>=c;a--)
const int N=10010;
int a[N];
priority_queue<int> Q;
bool cmp(int a,int b){
	return a>b;
} 
inline int read(){
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();		
	}
	while(ch>='0'&&ch<='9'){
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*f;
}
int main(){
	int n,k;
	n=read();
	k=read();
	fo(i,1,n){
		a[i]=read();
	}
	stable_sort(a+1,a+n+1,cmp);
	if((a[1]+a[n])%k==k-1){
	    int ans1=0,ans2=0;
	    fo(i,1,n){
	    	Q.push(a[i]);
	    }
	    fo(i,1,n-1){
	    	int first=Q.top();
	    	Q.pop();
		    int second=Q.top();
		    Q.pop();
	        int mid=(first+second)/k;
	    	Q.push(mid);
	    }
	    ans1=Q.top();
	    while(!Q.empty()){
	        Q.pop();
	    }
	    a[1]=(a[1]+a[n])/k;
		a[n]=0;
		--n;
		fo(i,1,n){
		    Q.push(a[i]);
		}
	    fo(i,1,n-1){
	    	int first=Q.top();
	    	Q.pop();
	    	int second=Q.top();
	    	Q.pop();
	    	int mid=(first+second)/k;
		    Q.push(mid);
	    }
	    ans2=Q.top();
	    cout<<min(ans1,ans2)<<endl;
	    return 0;
	}
	fo(i,1,n){
		Q.push(a[i]);
	}
	fo(i,1,n-1){
		int first=Q.top();
		Q.pop();
		int second=Q.top();
		Q.pop();
		int mid=(first+second)/k;
		Q.push(mid);
	}
	int ans=Q.top();
	cout<<ans<<endl;
	return 0;
} 
2022/8/12 12:03
加载中...