79152024-01-11 22:26:34adamBenzinkút üzemeltetés (55)cpp17Accepted 55/5528ms19064 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> dist, profit;
int stop_count, min_dist;

vector<vector<pair<int, int>>> memo;

int solve(int n, int before) {
    if(n == stop_count+1) return 0;
    else if (memo[n][before] != pair(-1, -1)) return memo[n][before].first;
    int answer = 0;

    int b = solve(n + 1, before);

    if (dist[n] - dist[before] >= min_dist) {
        answer = profit[n] + solve(n+1, n);
    }
    if (answer > b) {
        memo[n][before] = {answer, 0};
    } else {
        memo[n][before] = {b, 1};
    }
    return memo[n][before].first;
}



int main() {

    cin >> stop_count >> min_dist;
    dist.assign(stop_count +1, 0);
    profit.assign(stop_count +1, 0);
    dist[0] = 0 - min_dist - 1;
    profit[0] = 0 - min_dist - 1;
    memo.assign(stop_count + 1, vector<pair<int, int>>(stop_count+1, {-1, -1}));


    for (int i = 1; i <= stop_count; i++) {
        cin >> dist[i] >> profit[i];
    }

    cout << solve(1, 0) << endl;

    vector<int> stations;
    int actual = 1;
    int before = 0;
    while(actual <= stop_count) {
        if(memo[actual][before].second == 0) {
            stations.push_back(actual);
            before = actual++;
        } else {
            actual++;
        }
    }
    cout << stations.size() << " ";
    for (int x : stations) {
        cout << x << " ";
    }


}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1816 KiB
2Accepted0/028ms17696 KiB
3Accepted3/33ms2212 KiB
4Accepted3/32ms2324 KiB
5Accepted3/33ms2528 KiB
6Accepted3/33ms2740 KiB
7Accepted3/32ms2828 KiB
8Accepted3/32ms2828 KiB
9Accepted3/33ms3168 KiB
10Accepted3/33ms3288 KiB
11Accepted3/33ms3612 KiB
12Accepted3/38ms7280 KiB
13Accepted4/410ms8948 KiB
14Accepted4/416ms10992 KiB
15Accepted5/517ms13092 KiB
16Accepted6/624ms15796 KiB
17Accepted6/627ms19064 KiB