30702023-02-13 19:06:37horvathabelBenzinkút üzemeltetés (55)cpp17Accepted 55/554ms6032 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k; 
	cin>>n>>k; 
	vector<int> he={-1*k-1}; 
	vector<int> h={0}; 
	for (int i=0; i<n;i++){
		int t,ha;
		cin>>t>>ha;
		he.push_back(t);
		h.push_back(ha);
	}
	
	vector<int> dp(n+1); 
	dp[0]=0; 
	vector<vector<int>> elment(n+1); 
	for (int i=1; i<=n;i++){
		for (int j=i-1; j>=0; j--){
			if (he[j]<=he[i]-k){
				if (dp[i-1]>dp[j]+h[i]){
					dp[i]=dp[i-1];
					elment[i]=elment[i-1];
					break;
				}
				else{
					dp[i]=dp[j]+h[i];
					elment[i]=elment[j];
					elment[i].push_back(i);
					break;
				}
				
			}
		
		}
	}
	cout<<dp[n]<<endl;
	cout<<elment[n].size()<<" ";
	for (int x:elment[n]) cout<<x<<" "; 
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1812 KiB
2Accepted0/04ms4520 KiB
3Accepted3/33ms2220 KiB
4Accepted3/33ms2580 KiB
5Accepted3/33ms2696 KiB
6Accepted3/33ms2908 KiB
7Accepted3/33ms3040 KiB
8Accepted3/33ms3020 KiB
9Accepted3/33ms3044 KiB
10Accepted3/33ms3176 KiB
11Accepted3/33ms3528 KiB
12Accepted3/33ms4144 KiB
13Accepted4/43ms4744 KiB
14Accepted4/44ms5076 KiB
15Accepted5/54ms5352 KiB
16Accepted6/64ms5804 KiB
17Accepted6/64ms6032 KiB