39362023-03-05 22:36:24SleepyOverlordSípálya (55 pont)cpp17Elfogadva 55/5582ms9392 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

#define IN_FILE "a.in"
#define OUT_FILE "a.out"

template <typename T>
void PR(T var1)
{
	cout << var1 <<endl;
}
template <typename T, typename... Types>
void PR(T var1, Types... var2)
{
	cout << var1;
	PR(var2...);
}

int n, k;
VI a;
deque <int> dq;
VLL sum;

int main()
{
	cin >> n >> k;
	a.RS(n + 1);
	sum.RS(n + 1);
	FOR(i, 1, n)
	{
		cin >> a[i];
		a[i] += i;
		sum[i] = sum[i - 1] + a[i];
	}

	FOR(i, 1, k)
	{
		while (!dq.empty() && a[dq.back()] < a[i]) dq.pop_back();
		dq.PB(i);
	}
	LL best = (LL)a[dq[0]] * k - sum[k];

	FOR(i, k + 1, n)
	{
		if (dq[0] == i - k) dq.pop_front();
		while (!dq.empty() && a[dq.back()] < a[i]) dq.pop_back();
		dq.PB(i);
		best = min(best, (LL)a[dq[0]] * k - (sum[i] - sum[i - k]));
	}
	PR(best);

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/03ms1812 KiB
2Elfogadva0/03ms2064 KiB
3Elfogadva2/23ms2288 KiB
4Elfogadva2/23ms2520 KiB
5Elfogadva2/23ms2564 KiB
6Elfogadva2/23ms2672 KiB
7Elfogadva3/33ms2888 KiB
8Elfogadva1/16ms3328 KiB
9Elfogadva1/16ms3528 KiB
10Elfogadva1/16ms3784 KiB
11Elfogadva1/16ms3996 KiB
12Elfogadva1/16ms3948 KiB
13Elfogadva1/16ms4044 KiB
14Elfogadva2/26ms4180 KiB
15Elfogadva2/26ms4140 KiB
16Elfogadva2/276ms8492 KiB
17Elfogadva2/275ms8520 KiB
18Elfogadva2/275ms8896 KiB
19Elfogadva3/376ms9024 KiB
20Elfogadva2/278ms8960 KiB
21Elfogadva2/276ms8872 KiB
22Elfogadva2/278ms9000 KiB
23Elfogadva2/278ms8912 KiB
24Elfogadva2/282ms8888 KiB
25Elfogadva2/278ms8892 KiB
26Elfogadva2/278ms9104 KiB
27Elfogadva2/276ms9152 KiB
28Elfogadva3/378ms9136 KiB
29Elfogadva3/376ms9140 KiB
30Elfogadva3/378ms9392 KiB