222232026-01-14 18:11:29algoproBenzinkút üzemeltetés (55)cpp17Wrong answer 8/552ms604 KiB
// UUID: 6e5dedbf-81c8-4ad0-929b-2673cced6bd7
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,k;
	cin >> n >> k;
	vector<pair<int,int>>bz(n);
	vector<int>tav(n);
	for(int i=0; i<n; i++){
		cin >> bz[i].first >> bz[i].second;
		tav[i]=bz[i].first;
	}
	vector<int>dp(n);
	vector<bool>vsz(n, false);
	dp[0]=bz[0].second;
	int l=0;
	for(int i=1; i<n; i++){
		//int j;
		while(bz[i].first-bz[l].first>=k && l<=i)l++;
		l--;
		if(l>=0){
		dp[i]=max(dp[i-1], bz[i].second+dp[l]);
		}
		else{
			dp[i]=max(dp[i-1], bz[i].second);
			l=0;
		} 
		if(dp[i]!=dp[i-1])vsz[i]=true;
		//cout << dp[i] << " ";
	}
	cout<< dp[n-1] << '\n';
	int maxi=0;
	vector<int> ans;
	int i=n-1;
	while(i>=0){
		if(vsz[i]){
			ans.push_back(i+1);
			int j=i-1;
			while(j>=0 && bz[i].first-bz[j].first<k)j--;
			i=j;
		}
		else i--;
	}
	cout << ans.size() << " ";
	for(int j=0; j<ans.size(); j++){cout << ans[j]<< " ";}
}
/*l=n-1;
	for(int i=n-1; i>0; i-- ){
		while(bz[i].first-bz[l].first>=k && l>=0)l--;
		l++;
		if(l<n){
		if(dp[i]!=dp[l])maxi ++; }
		else {l=n-1;}
	}
	cout << maxi << " ";
	for(int i=n-1; i>0; i-- ){
		while(bz[i].first-bz[l].first>=k && l>=0)l--;;
		l++;
		if(l<n){
		if(dp[i]!=dp[l])cout << i+1 << " "; }
		else l=n-1;
	}*/
SubtaskSumTestVerdictTimeMemory
base8/55
1Wrong answer0/01ms316 KiB
2Wrong answer0/02ms316 KiB
3Wrong answer0/31ms508 KiB
4Wrong answer0/31ms316 KiB
5Partially correct1/31ms384 KiB
6Wrong answer0/31ms316 KiB
7Partially correct1/31ms316 KiB
8Wrong answer0/31ms512 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/31ms316 KiB
11Wrong answer0/31ms396 KiB
12Wrong answer0/31ms412 KiB
13Wrong answer0/42ms316 KiB
14Wrong answer0/42ms604 KiB
15Wrong answer0/52ms316 KiB
16Partially correct3/62ms512 KiB
17Partially correct3/61ms316 KiB