40872023-03-13 13:29:39KaukazusSípálya (55 pont)cpp17Time limit exceeded 4/55472ms5048 KiB

#include <bits/stdc++.h>
#include <climits>
#include <deque>
#include <ostream>
#include <queue>
using namespace std;

int main() {
	int n,k;
	cin >> n >> k;

	deque<int> tomb;
	int max=0, hely, vegszamlalo=INT_MAX;
	for(int i=0;i<k-1;i++){
		int valt;
		cin >> valt;
		if(valt>max){
			max=valt;
			hely=i;
		}
		tomb.push_back(valt);
		cerr << valt;
	}
	for(int i=k-1;i<n;i++){
		
		cerr << endl;
		int valt, szamlalo=0;
		cin >> valt;
		tomb.push_back(valt);

		priority_queue<pair<int,int>> pq;

		for(int i=0;i<tomb.size();i++){
			pq.push(make_pair(tomb[i],i));
			cerr << tomb[i] << " ";
		}

		max=pq.top().first;
		hely=pq.top().second;

		cerr <<endl << max << " " << hely << " ";
		for(int x=0;x<=hely;x++){

			szamlalo+=abs(tomb[x]-max)+hely-x;
			cerr << szamlalo << endl;
		}
		for(int x=hely+1;x<k;x++){
			szamlalo+=max-tomb[x]+hely-x;
			cerr << x << " " << szamlalo << endl;
		}
		if(szamlalo<vegszamlalo){
			vegszamlalo=szamlalo;
		}
		tomb.pop_front();
	}
	cout << vegszamlalo;
}
SubtaskSumTestVerdictTimeMemory
base4/55
1Accepted0/03ms1808 KiB
2Accepted0/04ms2004 KiB
3Accepted2/265ms2244 KiB
4Accepted2/2115ms2452 KiB
5Time limit exceeded0/2455ms2616 KiB
6Time limit exceeded0/2467ms2852 KiB
7Time limit exceeded0/3442ms2456 KiB
8Time limit exceeded0/1435ms2480 KiB
9Time limit exceeded0/1453ms2472 KiB
10Time limit exceeded0/1451ms2708 KiB
11Time limit exceeded0/1460ms2808 KiB
12Time limit exceeded0/1458ms3156 KiB
13Time limit exceeded0/1462ms4176 KiB
14Time limit exceeded0/2444ms3324 KiB
15Time limit exceeded0/2467ms3244 KiB
16Time limit exceeded0/2469ms3528 KiB
17Time limit exceeded0/2456ms4728 KiB
18Time limit exceeded0/2465ms4904 KiB
19Time limit exceeded0/3456ms5048 KiB
20Time limit exceeded0/2472ms3804 KiB
21Time limit exceeded0/2455ms3544 KiB
22Time limit exceeded0/2458ms3584 KiB
23Time limit exceeded0/2460ms3572 KiB
24Time limit exceeded0/2456ms3460 KiB
25Time limit exceeded0/2467ms3920 KiB
26Time limit exceeded0/2446ms4008 KiB
27Time limit exceeded0/2423ms3984 KiB
28Time limit exceeded0/3458ms3992 KiB
29Time limit exceeded0/3433ms4556 KiB
30Time limit exceeded0/3444ms4772 KiB