結果

問題 No.3764 Graduation Live
コンテスト
ユーザー 👑 Nachia
提出日時 2026-10-09 23:04:37
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,037 ms / 2,000 ms
+ 713µs
コード長 2,275 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 589 ms
コンパイル使用メモリ 107,896 KB
実行使用メモリ 15,064 KB
最終ジャッジ日時 2026-10-09 23:05:14
合計ジャッジ時間 35,527 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
// disable assert
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }

V<array<ll,9>> diffs;

#define ENUM_REP(i) for(ll i=-2; i<=2; i++)

void enum_diff(){
  ENUM_REP(a) ENUM_REP(b) ENUM_REP(c) ENUM_REP(ab) ENUM_REP(bc) ENUM_REP(ca){
    if(a+b+c+ab+bc+ca != 1) continue;
    if((a < 0 || b < 0) && ab > 0) continue;
    if((b < 0 || c < 0) && bc > 0) continue;
    if((c < 0 || a < 0) && ca > 0) continue;
    diffs.push_back({ a, b, c, ab, ca, bc, a+ab+ca, b+ab+bc, c+ca+bc });
  }
}

void testcase(){
  ll N, A, B, C; cin >> N >> A >> B >> C;
  array<V<ll>, 6> score;
  REP(i,N){
    ll t,v; cin >> t >> v; t--;
    score[t].push_back(v);
  }

  ll semiINF = INF / 10;

  REP(t,6){
    sort(score[t].rbegin(), score[t].rend());
    V<ll> sum;
    REP(i,2) sum.push_back(-semiINF);
    sum.push_back(0);
    for(auto a : score[t]) sum.push_back(sum.back() + a);
    REP(i,2) sum.push_back(-semiINF);
    swap(score[t], sum);
  }

  // REP(t,6){ for(auto a : score[t]) cout << a << " "; cout << endl; }

  V<ll> ans;
  array<ll, 9> p; p.fill(0);
  REP(i,6) p[i] = 2;
  while(1){
    ll maxans = -INF;
    ll argmax = -1;
    REP(i,diffs.size()){
      if(p[6] + diffs[i][6] > A) continue;
      if(p[7] + diffs[i][7] > B) continue;
      if(p[8] + diffs[i][8] > C) continue;
      ll c = 0;
      REP(t,6) c += score[t][p[t] + diffs[i][t]];
      if(maxans < c){ maxans = c; argmax = i; }
    }
    // cout << "maxans = " << maxans << " , argmax = "; REP(i,6) cout << diffs[argmax][i] << " "; cout << endl;
    if(maxans < -semiINF / 3) break;

    ans.push_back(maxans);
    REP(t,9) p[t] += diffs[argmax][t];
  }
  
  cout << ans.size();
  REP(i,ans.size()){
    cout << " " << ans[i];
  } cout << "\n";
}

int main(){
  cin.tie(0)->sync_with_stdio(0);
  enum_diff();
  // cout << diffs.size() << endl;
  ll T; cin >> T; REP(t,T)
  testcase();
  return 0;
}
0