/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 348.0 KiB
#2 Accepted 9ms 532.0 KiB
#3 Accepted 20ms 592.0 KiB
#4 Accepted 14ms 608.0 KiB
#5 Accepted 15ms 1000.0 KiB
#6 Accepted 19ms 2.02 MiB
#7 Accepted 20ms 3.492 MiB
#8 Accepted 15ms 3.539 MiB
#9 Accepted 5ms 532.0 KiB

Code

#include<bits/stdc++.h>
#define ll                  long long
#define nl                  '\n'
#define F                   first
#define S                   second
#define all(a)              (a.begin()),(a.end())
#define UNIQUE(X)           (X).erase(unique(all(X)),(X).end())
#define SORT_UNIQUE(c)      (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define ms(a,b)             memset(a, b, sizeof(a))
#define Input               freopen("in.txt","r",stdin)
#define Output              freopen("out.txt","w",stdout)
#define MOD                 1000000007
using namespace std;


const int N = 2e5 + 5;
ll sum[N];

void Solve(int t)
{
	ll n, k, d;
	cin >> n >> k >> d;
	std::vector<ll> v(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		sum[i] = sum[i - 1] + v[i];
	}
	vector<pair<ll, ll>> res;

	for (int i = k; i <= n; i++)
	{
		ll cnt = sum[i] - sum[i - k];
		if (cnt % d == 0) {
			res.push_back({cnt == k, -(i - k + 1)});
		}
	}
	if (res.size() == 0) {
		cout << "-1\n";

	}
	else {
		sort(all(res));
		reverse(all(res));
		cout << -res[0].S << nl;
	}


}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t, T = 1;
	cin >> T;
	for (t = 1; t <= T; t++)
		Solve(t);
	return 0;
}

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 15:41:31
Judged At
2025-04-06 15:41:31
Judged By
Score
100
Total Time
20ms
Peak Memory
3.539 MiB