为什么同样的思路在abc227_d能过 在这WA
查看原帖
为什么同样的思路在abc227_d能过 在这WA
1284815
canwen楼主2025/7/28 12:47

Accept

这题只过了 Sub 1,其他 WA,这题我的代码。

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define int __int128
//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define pc putchar
int in(){
	char a=getchar();int k=0,kk=1;
	while(!(a>='0'&&a<='9')) {if(a == '-') kk = -1;a = getchar();}
	while(a>='0'&&a<='9') k = k*10 + a - '0', a = getchar();
	return k*kk;
}
void out(int a){
	if(a < 0) pc('-'), a= -a;
	if(a > 9) out(a/10);
	pc('0'+a%10);
}
#define fst first
#define snd second
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define _rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define _reps(i,a,b,c) for(int i=(a);i<=(b);c)
#define _rreps(i,a,b,c) for(int i=(a);i>=(b);c)
#define _graph(i) for(int i=head[u];i;i=e[i].nxt)
#define mp make_pair
#define pint pair<int,int>
#define i128 __int128
#define i64 long long
#define pb emplace_back
#define FRR(file) freopen(file,"r",stdin)
#define FRW(file) freopen(file,"w",stdout)
#define nowtime (double)clock()/CLOCKS_PER_SEC
const int N = 2e5 + 5;
int n,t,a[N];
bool check(int x){
	int cnt = 0, cnt1 = 0;
	_rep(i,1,n){
		if(a[i] >= x){
			cnt++;
		}else cnt1 += a[i];
	}
	return cnt1 >=  (t-cnt) * x;
} 
signed main(){
	int ans = 0;
	n = in(), t = in();
	_rep(i,1,n) a[i] = in();
	int l = 0, r = 5e5 * 1e6; // At 那题就改了上届而已
	while(l<=r){
		int m = l + r >> 1ll;
		if(check(m)) ans = m, l = m + 1;
		else r = m - 1;
	}
	out(ans);
	return 0;
}
2025/7/28 12:47
加载中...