Language: C++

#include <functional>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <valarray>
#include <vector>

std::vector<std::string> GetInputValues();
std::valarray<int> DeriveSumArr1();
std::valarray<int> DeriveSumArr2();

std::string InputPattern = "InputX";

std::vector<std::string> GetInputValues()
{
    std::vector<std::string> InputValuesVect;

    if (InputPattern == "Input1") {
        InputValuesVect.push_back("2");
        InputValuesVect.push_back("3 1 4 1 5 9");
        //1
    }
    else if (InputPattern == "Input2") {
        InputValuesVect.push_back("1");
        InputValuesVect.push_back("1 2 3");
        //-1
    }
    else if (InputPattern == "Input3") {
        InputValuesVect.push_back("3");
        InputValuesVect.push_back("8 2 2 7 4 6 5 3 8");
        //5
    }
    else { //実際の入力
        while (true) {
            std::string wkStr;
            std::getline(std::cin,wkStr);
            if(std::cin.eof()) break;
            InputValuesVect.push_back(wkStr.c_str());
        }
    }

    return InputValuesVect;
}

int N;
int UB;
std::valarray<int> AArr;

int main()
{
    std::vector<std::string> InputVect = GetInputValues();
    N=atoi(InputVect.at(0).c_str());
    UB=3*N-1;
    AArr = std::valarray<int> (UB+1);
    int CurrInd=0;

    std::istringstream iss1(InputVect.at(1));
    while(iss1.eof() == false){
        int wkInt;
        iss1 >> wkInt;
        AArr[CurrInd++]=wkInt;
    }

    std::valarray<int> SumArr1=DeriveSumArr1();
    //for(int I=0;I<=(int)SumArr1.size()-1;I++){
    //    printf("%d,",SumArr1[I]);
    //}
    //puts("");

    std::valarray<int> SumArr2=DeriveSumArr2();
    //for(int I=0;I<=(int)SumArr2.size()-1;I++){
    //    printf("%d,",SumArr2[I]);
    //}
    //puts("");

    int Answer=INT_MIN;
    for(int I=N;I<=2*N;I++){
        int AnswerKouho=SumArr1[I-1]-SumArr2[I];
        if(Answer<AnswerKouho){
            Answer=AnswerKouho;
        }
    }
    printf("%d\n",Answer);
}

//添字ごとのTopNの合計の配列を返す(前半部分)
std::valarray<int> DeriveSumArr1()
{
    std::valarray<int> SumArr1(UB+1);

    std::priority_queue<int,std::vector<int>, std::greater<int> > Que;

    int SumVal=0;
    for(int I=0;I<=UB;I++){
        Que.push(AArr[I]);
        SumVal+=AArr[I];

        if((int)Que.size()>N){
            SumVal-=Que.top();
            Que.pop();
        }
        SumArr1[I]=SumVal;
    }
    return SumArr1;
}

//添字ごとのTopNの合計の配列を返す(後半部分)
std::valarray<int> DeriveSumArr2()
{
    std::valarray<int> SumArr2(UB+1);

    std::priority_queue<int> Que;

    int SumVal=0;
    for(int I=UB;0<=I;I--){
        Que.push(AArr[I]);
        SumVal+=AArr[I];

        if((int)Que.size()>N){
            SumVal-=Que.top();
            Que.pop();
        }
        SumArr2[I]=SumVal;
    }
    return SumArr2;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:79:16: error: 'INT_MIN' was not declared in this scope
   79 |     int Answer=INT_MIN;
      |                ^~~~~~~
a.cc:9:1: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    8 | #include <valarray>
  +++ |+#include <climits>
    9 | #include <vector>