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<long long> SumArr1=DeriveSumArr1();
    //for(int I=0;I<=(int)SumArr1.size()-1;I++){
    //    printf("%d,",SumArr1[I]);
    //}
    //puts("");

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

    long long Answer=LLONG_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<long long> DeriveSumArr1()
{
    std::valarray<long long> SumArr1(UB+1);

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

    long long 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<long long> DeriveSumArr2()
{
    std::valarray<long long> SumArr2(UB+1);

    std::priority_queue<long long> Que;

    long long 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:67:51: error: conversion from 'valarray<int>' to non-scalar type 'valarray<long long int>' requested
   67 |     std::valarray<long long> SumArr1=DeriveSumArr1();
      |                                      ~~~~~~~~~~~~~^~
a.cc:73:51: error: conversion from 'valarray<int>' to non-scalar type 'valarray<long long int>' requested
   73 |     std::valarray<long long> SumArr2=DeriveSumArr2();
      |                                      ~~~~~~~~~~~~~^~
a.cc:79:22: error: 'LLONG_MIN' was not declared in this scope
   79 |     long long Answer=LLONG_MIN;
      |                      ^~~~~~~~~
a.cc:9:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    8 | #include <valarray>
  +++ |+#include <climits>
    9 | #include <vector>
a.cc: At global scope:
a.cc:90:26: error: ambiguating new declaration of 'std::valarray<long long int> DeriveSumArr1()'
   90 | std::valarray<long long> DeriveSumArr1()
      |                          ^~~~~~~~~~~~~
a.cc:12:20: note: old declaration 'std::valarray<int> DeriveSumArr1()'
   12 | std::valarray<int> DeriveSumArr1();
      |                    ^~~~~~~~~~~~~
a.cc:111:26: error: ambiguating new declaration of 'std::valarray<long long int> DeriveSumArr2()'
  111 | std::valarray<long long> DeriveSumArr2()
      |                          ^~~~~~~~~~~~~
a.cc:13:20: note: old declaration 'std::valarray<int> DeriveSumArr2()'
   13 | std::valarray<int> DeriveSumArr2();
      |                    ^~~~~~~~~~~~~