제출 #1318861

#제출 시각아이디문제언어결과실행 시간메모리
1318861killerzaluuBouquet (EGOI24_bouquet)C++20
8 / 100
121 ms23108 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> l(n + 2), r(n + 2); // 1-indexed
    for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];

    vector<int> dp(n + 2, 1); // dp[i] = 1 initially
    vector<vector<int>> sad(n + 2); // sad[i] = flowers that become available at i

    for (int i = 1; i <= n; i++) {
        int pos = i + l[i] + 1;
        if (pos <= n) sad[pos].push_back(i);
    }

    multiset<int> happy; // keeps all available dp[x]
    int ans = 1;

    for (int i = 2; i <= n; i++) {
        // insert all dp[x] whose flowers become available at index i
        for (int x : sad[i]) happy.insert(dp[x]);

        // update dp[i] using the maximum available dp[x] + 1
        if (!happy.empty()) dp[i] = max(dp[i], *happy.rbegin() + 1);

        ans = max(ans, dp[i]);
    }

    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...