/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 2ms 540.0 KiB
#4 Accepted 2ms 576.0 KiB
#5 Accepted 3ms 480.0 KiB
#6 Accepted 2ms 324.0 KiB
#7 Accepted 75ms 968.0 KiB
#8 Accepted 2ms 532.0 KiB
#9 Accepted 62ms 788.0 KiB
#10 Accepted 37ms 788.0 KiB

Code

#include <bits/stdc++.h>

using namespace std;

#define int int64_t
#define el '\n'

const int N = 5e4 + 1;

template<int sz>
void work (int n) {
  if (n > sz) {
    work<min(N, sz * 2)> (n);
    return;
  }
  bitset<sz + 5> b;
  b.set(0);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b |= b << a[i];
  }
  for (int i = n; i >= 0; i--) {
    if (b[i]) {
      cout << i << el;
      return;
    }
  }
}

void run_case(int tc) {
  int n;
  cin >> n;
  work <1> (n);
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int _t = 1;
  cin >> _t;
  for (int i = 1; i <= _t; i++) {
    run_case(i);
  }
}

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 16:27:01
Judged At
2026-01-06 16:27:01
Judged By
Score
100
Total Time
75ms
Peak Memory
968.0 KiB