Language: C++

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF+7;
const LL LLINF = 1e18;

int main(void) {
    int N, x;
    cin >> N >> x;
    VL a(N);
    REP (i, N) cin >> a[i];
    copy_n(ALL(a), back_inserter(a));
    LL ans = LLINF;
    VL b(N, LLINF);
    REP (k, N) {
        LL sum = k*x;
        REP (i, N) {
            int id = (i-k+N);
            b[i] = min<LL>(b[i], a[id]);
            sum += b[i];
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


Compiler output:
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of '_OIter std::copy_n(_IIter, _Size, _OIter) [with _IIter = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _Size = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _OIter = back_insert_iterator<vector<long long int> >]':
a.cc:63:11:   required from here
   63 |     copy_n(ALL(a), back_inserter(a));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:708:47: error: no matching function for call to '__size_to_integer(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >&)'
  708 |       const auto __n2 = std::__size_to_integer(__n);
      |                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:1036:3: note: candidate: 'constexpr int std::__size_to_integer(int)'
 1036 |   __size_to_integer(int __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1036:25: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'int'
 1036 |   __size_to_integer(int __n) { return __n; }
      |                     ~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1038:3: note: candidate: 'constexpr unsigned int std::__size_to_integer(unsigned int)'
 1038 |   __size_to_integer(unsigned __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1038:30: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'unsigned int'
 1038 |   __size_to_integer(unsigned __n) { return __n; }
      |                     ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1040:3: note: candidate: 'constexpr long int std::__size_to_integer(long int)'
 1040 |   __size_to_integer(long __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1040:26: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'long int'
 1040 |   __size_to_integer(long __n) { return __n; }
      |                     ~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1042:3: note: candidate: 'constexpr long unsigned int std::__size_to_integer(long unsigned int)'
 1042 |   __size_to_integer(unsigned long __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1042:35: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'long unsigned int'
 1042 |   __size_to_integer(unsigned long __n) { return __n; }
      |                     ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1044:3: note: candidate: 'constexpr long long int std::__size_to_integer(long long int)'
 1044 |   __size_to_integer(long long __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1044:31: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'long long int'
 1044 |   __size_to_integer(long long __n) { return __n; }
      |                     ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1046:3: note: candidate: 'constexpr long long unsigned int std::__size_to_integer(long long unsigned int)'
 1046 |   __size_to_integer(unsigned long long __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1046:40: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'long long unsigned int'
 1046 |   __size_to_integer(unsigned long long __n) { return __n; }
      |                     ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1050:3: note: candidate: 'constexpr __int128 std::__size_to_integer(__int128)'
 1050 |   __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1050:44: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to '__int128'
 1050 |   __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) { return __n; }
      |                                            ^
/usr/include/c++/14/bits/stl_algobase.h:1052:3: note: candidate: 'constexpr __int128 unsigned std::__size_to_integer(__int128 unsigned)'
 1052 |   __size_to_integer(unsigned __GLIBCXX_TYPE_INT_N_0 __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1052:53: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to '__int128 unsigned'
 1052 |   __size_to_integer(unsigned __GLIBCXX_TYPE_INT_N_0 __n) { return __n; }
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1074:3: note: candidate: 'constexpr long long int std::__size_to_integer(float)'
 1074 |   __size_to_integer(float __n) { return (long long)__n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1074:27: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'float'
 1074 |   __size_to_integer(float __n) { return (long long)__n; }
      |                     ~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1076:3: note: candidate: 'constexpr long long int std::__size_to_integer(double)'
 1076 |   __size_to_integer(double __n) { return (long long)__n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1076:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'double'
 1076 |   __size_to_integer(double __n) { return (long long)__n; }
      |                     ~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1078:3: note: candidate: 'constexpr long long int std::__size_to_integer(long double)'
 1078 |   __size_to_integer(long double __n) { return (long long)__n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1078:33: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'long double'
 1078 |   __size_to_integer(long double __n) { return (long long)__n; }
      |                     ~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1081:3: note: candidate: 'constexpr long long int std::__size_to_integer(__float128)'
 1081 |   __size_to_integer(__float128 __n) { return (long long)__n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1081:32: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to '__float128'
 1081 |   __size_to_integer(__float128 __n) { return (long long)__n; }
      |                     ~~~~~~~~~~~^~~