https://ac.nowcoder.com/acm/contest/332/H

C++版本一

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++) 
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f)) 
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x); 
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x); 
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long 
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = 0,f = 1;char c = getchar();while (c<'0' || c>'9'){if (c == '-') f = -1;c = getchar();}
while (c >= '0'&&c <= '9'){x = x * 10 + c - '0';c = getchar();}return x*f;}
const double eps = 1e-9;
const int maxn = 2010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int N,M,K;
const int SP = 20;
LL a[maxn];
LL X;
LL MIN[maxn][SP];
int mm[maxn];
void initRMQ(int n,LL b[]){
    for(int i = 1; i <= n ; i ++){
        for(int j = 0 ; j < SP; j ++){
            MIN[i][j] = INF;
        }
    }
    mm[0] = -1;
    for(int i = 1; i <= n ; i ++){
        mm[i] = ((i & (i - 1)) == 0)?mm[i - 1] + 1:mm[i - 1];
        MIN[i][0] = b[i];
    }
    for(int j = 1; j <= mm[n]; j ++){
        for(int i = 1; i + (1 << j) - 1 <= n; i ++){
            MIN[i][j] = min(MIN[i][j - 1],MIN[i + (1 << (j - 1))][j - 1]);
        }
    }
}
int rmq(int x,int y){
    int k = mm[y - x + 1];
    return min(MIN[x][k],MIN[y - (1 << k) + 1][k]);
}
int main(){
    Sca(N); Scl(X);
    for(int i = 1; i <= N ; i ++) Scl(a[i]);
    LL ANS = 1e18;
    initRMQ(N,a);
    for(int len = 1; len <= N ; len ++){
        LL sum = (len - 1) * X;
        for(int i = 1; i <= N ; i ++){
            LL ans = INF;
            if(i - len + 1 < 1){
                ans = min(rmq(i - len + 1 + N,N),rmq(1,i));
            }else{
                ans = rmq(i - len + 1,i);
            }
            sum += ans;
        }
        ANS = min(ANS,sum);
    }
    Prl(ANS);
    return 0;
}