Language: C++


#include <iostream>

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 member function 'void ABC172::C::Run()':
a.cc:16:12: error: 'vector' is not a member of 'std'
   16 |       std::vector<int> Ai = {};
      |            ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <iostream>
  +++ |+#include <vector>
    3 | 
a.cc:16:19: error: expected primary-expression before 'int'
   16 |       std::vector<int> Ai = {};
      |                   ^~~
a.cc:17:12: error: 'vector' is not a member of 'std'
   17 |       std::vector<int> Bi = {};
      |            ^~~~~~
a.cc:17:12: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:17:19: error: expected primary-expression before 'int'
   17 |       std::vector<int> Bi = {};
      |                   ^~~
a.cc:25:7: error: 'Ai' was not declared in this scope
   25 |       Ai.reserve(N_MAX);
      |       ^~
a.cc:26:7: error: 'Bi' was not declared in this scope
   26 |       Bi.reserve(N_MAX);
      |       ^~
a.cc: In lambda function:
a.cc:51:22: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]
   51 |         for (int i=0;i<v1end :++i)
      |                      ^
a.cc:51:30: error: expected ';' before ':' token
   51 |         for (int i=0;i<v1end :++i)
      |                              ^
a.cc:61:9: error: expected primary-expression before 'if'
   61 |         if (rest > 0) {
      |         ^~
a.cc:61:9: error: expected ';' before 'if'
a.cc:61:9: error: expected primary-expression before 'if'
a.cc:61:9: error: expected ')' before 'if'
a.cc:51:13: note: to match this '('
   51 |         for (int i=0;i<v1end :++i)
      |             ^