/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 5ms 532.0 KiB
#3 Accepted 6ms 764.0 KiB
#4 Accepted 6ms 532.0 KiB
#5 Accepted 4ms 532.0 KiB
#6 Accepted 18ms 532.0 KiB
#7 Accepted 94ms 584.0 KiB
#8 Accepted 10ms 532.0 KiB
#9 Accepted 72ms 576.0 KiB
#10 Accepted 53ms 584.0 KiB

Code

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

#define vi vector<int>
#define PB push_back
#define vll vector<long long>
#define ll long long
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define ld long double
#define vld vector<long double>

const ll mod = 998244353;
const ll MOD = 1e9 + 7;

ll sum(ll n){
    return (n * (n + 1)) / 2ll;
}

void solve(int tst){
    
    int n;
    cin >> n;

    bitset<50001> dp(0);
    dp[0] = true;

    int x;
    for (int i = 0; i < n; i++){
        cin >> x;
        if (x <= n) dp = (dp | (dp << x));
    }

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

}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // pre();
    int tc = 1;
    cin >> tc;
    for (int i = 1; i <= tc; i++){
        solve(i);
    }
    return 0;
}

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:50:18
Judged At
2026-01-06 15:50:18
Judged By
Score
100
Total Time
94ms
Peak Memory
764.0 KiB