/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 448.0 KiB
#3 Wrong Answer 1ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll N = 2e5+7;
ll node[N];

ll query(ll index) {
    ll ans = 0;
    while(index > 0) {
        ans = max(ans, node[index]);
        index -= index & (-index);
    }
    return ans;
}

void update(ll index, ll value, ll n) {
    while(index <= n) {
        node[index] = max(node[index], value);
        index += index & (-index);
    }
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tc; cin >> tc;

    test:
    while(tc--) {
        ll n; cin >> n;
        for (ll i = 0; i <= n; i++) node[i] = 0;

        ll a[n], b[n];
        for (auto &u : a) cin >> u;
        for (auto &u : b) cin >> u;

        ll temp[n];
        for (ll i = 0; i < n; i++) temp[i] = a[i];
        for (ll i = 0; i < n; i++) a[i] = lower_bound(temp, temp+n, a[i]) - temp + 1;
        
        ll dp[n] = {0}, mxAns = 0;
        for (ll i = 0; i < n; i++) { 
            ll best = query(a[i]-1) + b[i];
            dp[i] = best;
            update(a[i], best, n);
            mxAns = max(mxAns, best);
        }

        ll current = mxAns, indx = n;
        for (ll i = n-1; i >= 0; i--) {
            if (dp[i] == current) {
                indx = i;
                current -= b[i];
            }
        }

        cout << n - indx << "\n";
    }
}

Information

Submit By
Type
Submission
Problem
P1224 Maximize the max
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 17:13:39
Judged At
2025-09-02 17:13:39
Judged By
Score
1
Total Time
1ms
Peak Memory
532.0 KiB