49442023-04-07 17:47:58TomaSajtBenzinkút üzemeltetés (55)cpp17Accepted 55/554ms3640 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> tot_val(n), pos(n), val(n), prev(n, -1);

  for (int i = 0; i < n; i++) {
    cin >> pos[i] >> val[i];
    for (int j = 0; j < i; j++) {
      if (pos[i] - pos[j] >= k && tot_val[i] < tot_val[j]) {
        tot_val[i] = tot_val[j];
        prev[i] = j;
      }
    }
    tot_val[i] += val[i];
  }
  int curr = max_element(tot_val.begin(), tot_val.end()) - tot_val.begin();
  cout << tot_val[curr] << '\n';
  stack<int> res;
  while (curr != -1) {
    res.push(curr);
    curr = prev[curr];
  }
  cout << res.size();
  while (!res.empty()) {
    cout << ' ' << res.top() + 1;
    res.pop();
  }
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1824 KiB
2Accepted0/04ms2228 KiB
3Accepted3/33ms2200 KiB
4Accepted3/33ms2412 KiB
5Accepted3/32ms2492 KiB
6Accepted3/33ms2620 KiB
7Accepted3/33ms2836 KiB
8Accepted3/33ms3060 KiB
9Accepted3/33ms3148 KiB
10Accepted3/33ms3144 KiB
11Accepted3/33ms3236 KiB
12Accepted3/33ms3276 KiB
13Accepted4/43ms3356 KiB
14Accepted4/44ms3356 KiB
15Accepted5/54ms3360 KiB
16Accepted6/64ms3568 KiB
17Accepted6/64ms3640 KiB