QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687615 | #6433. Klee in Solitary Confinement | Kopicy | TL | 0ms | 0kb | C++23 | 1.3kb | 2024-10-29 20:00:23 | 2024-10-29 20:00:23 |
answer
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define sz(x) (int)x.size()
#define endl "\n"
const int N = 2e5, mod = 1e9 + 7, inf = 1e18;
int qpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
void solve() {
int n,k;
cin>>n>>k;
map<int,vector<int>> pos;
for(int i=1;i<=n;i++){
int x;cin>>x;
pos[x].push_back(i);
}
int ans=0;
for(auto &[x,vec]:pos){
ans=max(ans,sz(vec));
}
if(!k){
cout<<ans;
return;
}
for(auto &[x,vec]:pos){
int y=x+k;
vector<array<int,2>> tmp;
for(auto i:pos[x]) tmp.push_back({i,1});
for(auto i:pos[y]) tmp.push_back({i,-1});
sort(tmp.begin(),tmp.end(),[&](auto aa,auto bb){
return aa[0]<bb[0];
});
int p=0,ans1=0;
for(int i=0;i<sz(tmp);i++){
ans1=max(p+tmp[i][1],ans1);
p=max(p+tmp[i][1],0);
}
ans=max(ans,ans1+sz(pos[y]));
}
cout<<ans;
}
signed main() {
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tt = 1;
//cin >> tt;
rep(kase, 1, tt) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
5 2 2 2 4 4 4