60022023-10-15 12:29:28CattBenzinkút üzemeltetés (55)cpp17Wrong answer 0/553ms3500 KiB
#include <iostream>
#include <vector>
using namespace std;

struct RestStop {
    int distance;
    int profit;
};

int main() {
    int N, K;
    cin >> N >> K;

    vector<RestStop> restStops(N);
    for (int i = 0; i < N; i++) {
        cin >> restStops[i].distance >> restStops[i].profit;
    }

    long long maxProfit = 0;
    vector<int> locations;

    int currentLocation = 0;
    long long currentProfit = 0;

    for (int i = 0; i < N; i++) {
        int distance = restStops[i].distance - currentLocation;
        currentLocation = restStops[i].distance;

        if (distance >= K) {
            // Build a gas station at the current location
            maxProfit += currentProfit;
            currentProfit = 0;
            locations.push_back(currentLocation);
        }

        currentProfit = max(currentProfit, (long long)restStops[i].profit);
    }

    maxProfit += currentProfit;

    cout << maxProfit << endl;
    cout << locations.size() << " ";
    for (int i = 0; i < locations.size(); i++) {
        cout << locations[i] << " ";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Wrong answer0/03ms1808 KiB
2Accepted0/03ms2076 KiB
3Wrong answer0/33ms2272 KiB
4Wrong answer0/33ms2516 KiB
5Wrong answer0/32ms2564 KiB
6Wrong answer0/33ms2696 KiB
7Wrong answer0/33ms2944 KiB
8Wrong answer0/33ms3116 KiB
9Wrong answer0/32ms3200 KiB
10Wrong answer0/33ms3208 KiB
11Wrong answer0/32ms3200 KiB
12Wrong answer0/33ms3340 KiB
13Wrong answer0/43ms3448 KiB
14Wrong answer0/43ms3420 KiB
15Wrong answer0/53ms3424 KiB
16Wrong answer0/63ms3424 KiB
17Wrong answer0/63ms3500 KiB