Wrong Answer
Code
#include <bits/stdc++.h>
#define ll long long int
#define N "\n"
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--)
{
ll n,k,d;
cin>>n>>k>>d;
vector<ll>a(n);
vector<pair<ll,ll>>val;
for(ll i=0;i<n;i++)cin>>a[i];
ll sum=0;
map<ll,ll>mp;
for(ll i=0;i<n;i++){
if(i<k){
sum+=a[i];
mp[a[i]]++;
if(i==k-1){
if(sum%d==0){
if(mp[0]){
val.push_back({0,0});
}
else{
val.push_back({1,0});
}
}
}
continue;
}
mp[i-k]--;
sum-=a[i-k];
sum+=a[i];
mp[a[i]]++;
if(sum%d==0){
if(mp[0]){
val.push_back({0,i-k+1});
}
else{
val.push_back({1,i-k+1});
}
}
}
ll mx=0,mn=1e6;
sort(val.rbegin(),val.rend());
for(auto i:val){
if(i.first>=mx){
mx=i.first;
mn=min(mn,i.second);
}
}
if(mn==1e6){
cout<<-1<<N;
}
else{
cout<<mn+1<<N;
}
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1190 Segment Strength
- Contest
- Brain Booster #9
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-04-06 16:06:03
- Judged At
- 2025-04-06 16:06:03
- Judged By
- Score
- 75
- Total Time
- 82ms
- Peak Memory
- 14.062 MiB