AcWing 5995. 挖矿
原题链接
中等
作者:
Axel_D
,
2025-04-14 22:10:38
· 北京
,
所有人可见
,
阅读 1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e6;
int a[N], b[N];
int main(){
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
int n, m, i;
cin >> n >> m;
while(n--){
scanf("%d", &i);
if(i >= 0) a[i]++;
else b[-i]++;
}
for(i = 1; i < N; i++) {
a[i] += a[i-1];
b[i] += b[i-1];
}
int res = 0;
for(i = 0; i <= m; i++){
res = max(res, a[i] + b[(m-i)/2]);
res = max(res, a[i/2] + b[m-i]);
}
cout << res;
return 0;
}