Untitled
unknown
plain_text
10 months ago
806 B
7
Indexable
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> candles(N);
for (int i = 0; i < N; ++i) {
cin >> candles[i];
}
int low = 0;
int high = 0;
long long minTime = LLONG_MAX;
while (high < N) {
if (high - low + 1 < K) {
high++;
}
else {
int leftCandle = candles[low];
int rightCandle = candles[high];
long long time = abs(leftCandle) + (rightCandle - leftCandle);
minTime = min(minTime, time);
low++;
high++;
}
}
cout << minTime << endl;
return 0;
}Editor is loading...
Leave a Comment