216422026-01-13 17:39:53algoproBenzinkút üzemeltetés (55)cpp17Wrong answer 34/553ms1588 KiB
// UUID: 39b5e6ec-df6d-4af2-99ae-b6e7d751b05c
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k; cin >> n >> k;
	vector<pair<int, int>> stations(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> stations[i].first >> stations[i].second;
	}
	vector<vector<int>> indexes(n + 1);
	vector<int> dp(n + 1);
	for(int i = 1; i <= n; i++){
		if(stations[i].first - stations[1].first >= k){
			int prev = 0;
			int maxdist = stations[i].first - k;
			for(int j = 0; stations[j].first <= maxdist; j++){
				prev = j;
			}
			if(dp[i - 1] < stations[i].second + dp[prev]){
				dp[i] = dp[prev] + stations[i].second;
				indexes[i] = indexes[prev];
				indexes[i].push_back(i);
			}
			else{
				dp[i] = dp[i - 1];
				indexes[i] = indexes[i - 1];
			}
				
		}
		else{
			dp[i] = max(dp[i - 1], stations[i].second);
			indexes[i].push_back(i);
		}
	}
	cout << dp[n] << endl;
	cout <<  indexes[n].size() << " ";
	for(auto u : indexes[n]){
		cout << u << " ";
	}
}
SubtaskSumTestVerdictTimeMemory
base34/55
1Accepted0/01ms316 KiB
2Accepted0/03ms1588 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted3/31ms508 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Wrong answer0/31ms588 KiB
13Accepted4/42ms820 KiB
14Wrong answer0/42ms820 KiB
15Wrong answer0/52ms1076 KiB
16Accepted6/62ms1336 KiB
17Wrong answer0/63ms1440 KiB