Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- ll mod = 1e9 + 7;
- ll Test, cas;
- void solve()
- {
- ll n, x;
- cin >> n >> x;
- vector<vector<ll>> A(n, vector<ll>(n));
- for (ll i = 0; i < n; i++)
- {
- cin >> A[0][i];
- }
- ll ans = 1e18;
- vector<ll> mn(n, 1e18);
- for (ll i = 0; i < n; i++)
- {
- for (ll j = 0; j < n; j++)
- {
- mn[j] = min(mn[j], A[0][j]);
- }
- ans = min(ans, i * x + accumulate(mn.begin(), mn.end(), 0LL));
- for (ll j = 0; j < n; j++)
- {
- A[1][j] = A[0][(j - 1 + n) % n];
- }
- A[0] = A[1];
- }
- cout << ans << endl;
- return;
- }
- int main()
- {
- Test = 1;
- // cin >> Test;
- for (cas = 1; cas <= Test; cas++)
- solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment