14852022-11-18 16:39:211478Benzinkút üzemeltetés (55)cpp11Accepted 55/554ms4580 KiB
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int main()
{
    //ifstream cin("be.txt");
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i].first >> a[i].second;

    vector<int> dp(n + 1), os(n + 1), db(n + 1, 1);

    for (int i = 1; i <= n; i++)
    {
        dp[i] = a[i].second;
        for (int j = i - 1; j >= 1; j--)
        {
            int b = dp[j] + a[i].second;
            if (a[i].first - a[j].first >= k && b > dp[i])
            {
                dp[i] = b;
                db[i] = db[j] + 1;
                os[i] = j;
            }
        }
    }

    int maxi = 1;
    for (int i = 2; i <= n; i++)
    {
        if (dp[i] > dp[maxi])
        {
            maxi = i;
        }
    }

    cout << dp[maxi] << ln;
    cout << db[maxi] << " ";
    stack<int> s;
    while(maxi)
    {
        s.push(maxi);
        maxi = os[maxi];
    }
    while (!s.empty())
    {
        cout << s.top()<<" ";
        s.pop();
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1812 KiB
2Accepted0/04ms2180 KiB
3Accepted3/33ms2272 KiB
4Accepted3/33ms2344 KiB
5Accepted3/33ms2596 KiB
6Accepted3/33ms2808 KiB
7Accepted3/33ms2956 KiB
8Accepted3/33ms3176 KiB
9Accepted3/33ms3352 KiB
10Accepted3/33ms3592 KiB
11Accepted3/33ms3812 KiB
12Accepted3/33ms4028 KiB
13Accepted4/43ms4144 KiB
14Accepted4/43ms4244 KiB
15Accepted5/53ms4248 KiB
16Accepted6/64ms4468 KiB
17Accepted6/64ms4580 KiB