Language: C++


#include <iostream>
#include <vector>

namespace ABC172
{
  static const int N_MAX = 200001;

  class C
  {
  public:
    C() = default;
    ~C() = default;

    void Run()
    {
      std::vector<int> Ai = {};
      std::vector<int> Bi = {};

      int N = {};
      int M = {};
      int K = {};
      std::cin >> N;
      std::cin >> M;
      std::cin >> K;
      Ai.reserve(N_MAX);
      Bi.reserve(N_MAX);

      for (int i = 0; i < N; ++i)
      {
        int v;
        std::cin >> v;
        Ai.push_back(v);
      }
      for (int i = 0; i < M; ++i)
      {
        int v;
        std::cin >> v;
        Bi.push_back(v);
      }

      int answer = 0;

      int max_A = 0;
      int max_B = 0;

      auto Calc = [&](auto& v1, auto& v2, int v1end)
      {
        // v1優先で読み進める
        int rest = K;
        int num = 0;
        for (int i=0;i<v1end :++i)
        {
          auto v = v1.at(i);
          rest -= v;
          if (rest >= 0) {
            num++;
          } else {
            break;
          }
        }
        if (rest > 0) {
          for (auto v : v2)
          {
            rest -= v;
            if (rest >= 0) {
              num++;
            }
            else {
              break;
            }
          }
          return num;
        }
      };

      // Ai優先時の最善手を二部探索で探す
      int best_A = 0;
      {
        auto upper = Ai.size();
        auto lower = Ai.size() / 2;
        auto A1 = (Ai, Bi, upper);
        auto A2 = (Ai, Bi, lower);
        while (A1 != A2)
        {
          int dif = (upper - lower) * 0.5f;
          if (dif == 0) break;
          if (A1 > A2) {
            lower += dif;
            A2 = (Ai, Bi, lower);
          }
          else {
            upper -= dif;
            A1 = (Ai, Bi, upper);
          }
        }
        best_A = A1;
      }

      int best_B = 0;
      {
        auto upper = Bi.size();
        auto lower = Bi.size() / 2;
        auto A1 = (Bi, Ai, upper);
        auto A2 = (Bi, Ai, lower);
        while (A1 != A2)
        {
          int dif = (upper - lower) * 0.5f;
          if (dif == 0) break;
          if (A1 > A2) {
            lower += dif;
            A2 = (Bi,Ai, lower);
          }
          else {
            upper -= dif;
            A1 = (Bi, Ai, upper);
          }
        }
        best_B = A1;
      }

      answer = best_A > best_B ? best_A : best_B;

      std::cout << answer << std::endl;
    }
  };

}


int main()
{

  ABC172::C prob;
  prob.Run();

  return 0;
}



Compiler output:
a.cc: In lambda function:
a.cc:52:22: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]
   52 |         for (int i=0;i<v1end :++i)
      |                      ^
a.cc:52:30: error: expected ';' before ':' token
   52 |         for (int i=0;i<v1end :++i)
      |                              ^
a.cc:62:9: error: expected primary-expression before 'if'
   62 |         if (rest > 0) {
      |         ^~
a.cc:62:9: error: expected ';' before 'if'
a.cc:62:9: error: expected primary-expression before 'if'
a.cc:62:9: error: expected ')' before 'if'
a.cc:52:13: note: to match this '('
   52 |         for (int i=0;i<v1end :++i)
      |             ^