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.find(0)!=mp.end()){
val.push_back({0,0});
}
else{
val.push_back({1,0});
}
}
}
continue;
}
mp[a[i-k]]--;
sum-=a[i-k];
sum+=a[i];
mp[a[i]]++;
if(sum%d==0){
if(mp.find(0)!=mp.end()){
val.push_back({0,i-k+1});
}
else{
val.push_back({1,i-k+1});
}
}
}
if(val.size()==0){
cout<<-1<<N;
continue;
}
ll mx=-1e6,mn=200005;
vector<ll>indices;
sort(val.rbegin(), val.rend());
for(auto &i:val){
if(i.first>=mx){
mx=i.first;
mn=min(mn,i.second);
}
}
cout<<mn+1<<N;
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1190 Segment Strength
- Contest
- Brain Booster #9
- Language
- C++11 (G++ 13.2.0)
- Submit At
- 2025-04-06 16:20:04
- Judged At
- 2025-04-06 16:20:04
- Judged By
- Score
- 75
- Total Time
- 21ms
- Peak Memory
- 2.09 MiB