fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int n;
  8. int x;
  9. cin>>n>>x;
  10. int arr[n];
  11. for(int i=0; i<n; i++){
  12. cin>>arr[i];
  13. }
  14. vector<int> cost(n, INT_MAX);
  15. int ans= INT_MAX;
  16. for(int moves=0; moves<n; moves++){
  17. int sum=0;
  18. for(int j=0; j<n; j++){
  19. cost[j]= min(cost[j], arr[(j+moves)%n]);
  20. sum+=cost[j];
  21. }
  22. ans= min(ans, sum+x*moves);
  23. }
  24.  
  25. cout<<ans;
  26. return 0;
  27. }
Success #stdin #stdout 0s 4368KB
stdin
3 5
50 1 50
stdout
13