79152024-01-11 22:26:34adamBenzinkút üzemeltetés (55)cpp17Elfogadva 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 << " ";
    }


}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/03ms1816 KiB
2Elfogadva0/028ms17696 KiB
3Elfogadva3/33ms2212 KiB
4Elfogadva3/32ms2324 KiB
5Elfogadva3/33ms2528 KiB
6Elfogadva3/33ms2740 KiB
7Elfogadva3/32ms2828 KiB
8Elfogadva3/32ms2828 KiB
9Elfogadva3/33ms3168 KiB
10Elfogadva3/33ms3288 KiB
11Elfogadva3/33ms3612 KiB
12Elfogadva3/38ms7280 KiB
13Elfogadva4/410ms8948 KiB
14Elfogadva4/416ms10992 KiB
15Elfogadva5/517ms13092 KiB
16Elfogadva6/624ms15796 KiB
17Elfogadva6/627ms19064 KiB