QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665418 | #6433. Klee in Solitary Confinement | laing2122 | RE | 0ms | 0kb | C++17 | 1.4kb | 2024-10-22 12:32:08 | 2024-10-22 12:32:09 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<array>
#include<random>
#include<string>
#include<time.h>
#include<cstring>
#include<set>
#include<cmath>
#include<queue>
#define int long long
#define endl '\n'
#define F first
#define S second
#define sz size()
#define ln cout<<'\n'
#define B begin()
#define pb push_back
#define D end()
#define pii pair<int,int>
using namespace std;
const int N=3e6+10;
const int mod=1e9;
int cnt[N],ma[N];
int ji[N];
void solve()
{
int n,k;cin>>n>>k;
int d=1000010;
vector<int>a(n);
for(auto &x:a)
{
cin>>x;
ji[x]++;
}
if(k==0)
{
int ans=0;
for(int i=-1000000;i<=1000000;i++)
{
ans=max(ans,ji[i]);
}
cout<<ans<<'\n';
return ;
}
for(auto x:a)
{
if(x+k>=-1000000&&x+k<=1000000)
{
cnt[x+d]++;
ma[x+d]=max(ma[x+d],cnt[x+d]);
}
if(((x-k)>=-1000000)&&((x-k)<=1000000))
{
cnt[x-k+d]--;
cnt[x-k+d]=max(0ll,cnt[x-k+d]);
ma[x-k+d]=max(ma[x-k+d],cnt[x+d-k]);
}
//cout<<ma[x+d]<<' '<<cnt[x+d]<<'\n';
}
int ans=0;
for(int i=-1000000;i<=1000000;i++)
{
int x=i,y=ji[i];
if(((x-k)>=-1000000)&&((x-k)<=1000000))
{
ans=max(ans,y+ma[x-k+d]);//cout<<x<<' '<<y<<'\n';
}else ans=max(ans,y);
}
cout<<ans;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int tc=1;
//cin>>tc;
while(tc--)
{
solve();
}
//cout<<"dafc";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 2 2 2 4 4 4