/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 344.0 KiB
#2 Accepted 2ms 572.0 KiB
#3 Accepted 2ms 484.0 KiB
#4 Accepted 7ms 532.0 KiB
#5 Accepted 8ms 536.0 KiB
#6 Accepted 2ms 532.0 KiB
#7 Accepted 10ms 788.0 KiB
#8 Accepted 2ms 536.0 KiB
#9 Time Exceeded ≥2097ms ≥1.27 MiB
#10 Accepted 441ms 876.0 KiB

Code

#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <map>
#include <sstream>
#include <stack>
#include <bitset>
#include <random>

using ll = long long;

using namespace std;

constexpr int nm = 50002;

int n;
int a[nm];

void solve() {
    cin >> n;
    vector<int> cnt(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        if (a[i] <= n) cnt[a[i]]++;
    }

    vector<int> b;
    for (int i = 1; i <= n; ++i) {
        if (cnt[i] > 2) {
            int x = (cnt[i] - 1) / 2;
            if (2 * i <= n) cnt[2 * i] += x;
            cnt[i] -= 2 * x;
        }
        for (int j = 0; j < cnt[i]; ++j) b.push_back(i);
    }

    int m = b.size();
    vector<bool> dp(n + 1);
    dp[0] = 1;
    for (int i = 0; i < m; ++i) {
        for (int j = n; j >= b[i]; --j) {
            dp[j] = dp[j] || dp[j - b[i]];
        }
    }

    for (int i = n; i >= 0; --i) {
        if (dp[i]) {
            cout << i << "\n";
            return;
        }
    }
}

int main() {
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1234 E. Roy and Maximum Removals
Contest
Happy New Year 2026
Language
C++17 (G++ 13.2.0)
Submit At
2026-01-06 15:43:05
Judged At
2026-01-06 15:43:05
Judged By
Score
90
Total Time
≥2097ms
Peak Memory
≥1.27 MiB