Wrong Answer
Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(a) cout << #a << "-->" << (a) << '\n';
int main()
{
ios ::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
if (n == k)
{
ll sum=accumulate(v.begin(),v.end(),0LL);
cout<<sum<<'\n';
}
else if (n == 1)
{
cout<<v[0]<<'\n';
}
else
{
ll sum = INT_MAX;
for (int i = 0; i < n - 2; i++)
{
int j = i;
int times = 0;
ll ans = 0;
while (times < k)
{
ans += v[j];
j++;
times++;
if (times == k)
{
sum = min(ans, sum);
int u = j - 1;
ans -= v[u];
ans += v[j];
sum = min(ans, sum);
}
}
}
cout<<sum<<'\n';
// ll sum2 = INT_MAX;
// for (int i = n - 1; i >= k - 0 - 1; i--)
// {
// int j = i;
// int times = 0;
// ll ans = 0;
// while (times < k)
// {
// ans += v[j];
// j--;
// times++;
// if (times == k)
// {
// sum2 = min(ans, sum2);
// int u = j + 1;
// ans -= v[u];
// ans += v[j];
// sum2 = min(ans, sum2);
// }
// }
// }
// cout << min(sum, sum2) << '\n';
}
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1143 Plus of Pluses
- Contest
- LU IUJPC : Sylhet Division 2024
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-12-09 08:57:00
- Judged At
- 2024-12-09 08:57:00
- Judged By
- Score
- 0
- Total Time
- 2ms
- Peak Memory
- 540.0 KiB