123392024-12-12 19:46:33szasztundeSípálya (55 pont)cpp17Wrong answer 0/55136ms7480 KiB
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
	int n;
	cin>>n;
	int k;
	cin>>k;
	vector<long long> szm(n);
	vector<long long> pref(n);
	long long ossz=0;
	long long megold=0;
	long long megoldas=0;
	map<long long, int> vmi; // szám -> hány darab
	for(int i=0; i<n; i++){
		int a;
		cin>>a;
		ossz+=a+i;
		pref[i]=ossz;
		szm[i]=a+i;
	}
	for(int i=0; i<k; i++){
		vmi[szm[i]] += 1;
	}
	for(int i=0; i<n; i++) cout<<szm[i]<<" ";
	cout<<endl;
	for(int i=0; i<n; i++) cout<<pref[i]<<" ";
	cout<<endl;
	map<long long, int>::iterator it;
	for(it=vmi.begin();it!=vmi.end();it++)
        cout<<it->first<<"-"<<it->second<<"  ";
    cout<<endl;
	it = vmi.end();
	it--;
	megoldas=(k*it->first)-pref[k-1];
	for(int i=k; i<n; i++){
		vmi[szm[i-k]] -= 1;
		if(vmi[szm[i-k]] == 0) vmi.erase(szm[i-k]);
		vmi[szm[i]]+=1;
		it = vmi.end();
		it--;
		megold=(k*it->first)-pref[i]+pref[i-k];
		if(megold<megoldas){
			megoldas=megold;
		}
	}
	cout<<megoldas;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Wrong answer0/01ms500 KiB
2Wrong answer0/01ms508 KiB
3Wrong answer0/22ms320 KiB
4Wrong answer0/22ms320 KiB
5Wrong answer0/22ms320 KiB
6Wrong answer0/22ms320 KiB
7Wrong answer0/32ms320 KiB
8Wrong answer0/19ms644 KiB
9Wrong answer0/19ms568 KiB
10Wrong answer0/19ms756 KiB
11Wrong answer0/17ms568 KiB
12Wrong answer0/17ms572 KiB
13Wrong answer0/17ms596 KiB
14Wrong answer0/27ms560 KiB
15Wrong answer0/27ms560 KiB
16Wrong answer0/2128ms7136 KiB
17Wrong answer0/2129ms7132 KiB
18Wrong answer0/2128ms7392 KiB
19Wrong answer0/3130ms7404 KiB
20Wrong answer0/2133ms7392 KiB
21Wrong answer0/2129ms7388 KiB
22Wrong answer0/2128ms7224 KiB
23Wrong answer0/2131ms7392 KiB
24Wrong answer0/2136ms7480 KiB
25Wrong answer0/2133ms7396 KiB
26Wrong answer0/2133ms7392 KiB
27Wrong answer0/2130ms7228 KiB
28Wrong answer0/3130ms7224 KiB
29Wrong answer0/3128ms7228 KiB
30Wrong answer0/3133ms7480 KiB