fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int n;
  8. vector<int> plots;
  9. vector<int> tt;
  10. pair <long long int , vector<int>> pr[5010];
  11. int main()
  12. {
  13. cin >> n;
  14. plots.resize(n);
  15. for (int i = 0; i < n; i++)
  16. {
  17. cin >> plots[i];
  18. tt.push_back(plots[i]);
  19. }
  20. for(int i = 0; i < n; i++)
  21. {
  22. for(int j = 0; j < n; j++)
  23. plots[j]= tt[j];
  24. for (int j = i; j > 0; j--)
  25. {
  26. int temp = plots[j - 1] = min(plots[j], plots[j - 1]);
  27. pr[i].first += temp;
  28. pr[i].second.push_back(temp);
  29. }
  30. reverse(pr[i].second.begin(), pr[i].second.end());
  31. pr[i].first += plots[i];
  32. pr[i].second.push_back(plots[i]);
  33. for (int j = i; j < n - 1; j++)
  34. {
  35. int temp = plots[j + 1] = min(plots[j], plots[j + 1]);
  36. pr[i].first += temp;
  37. pr[i].second.push_back(temp);
  38. }
  39. }
  40. sort(pr,pr+n);
  41. for(int i = 0; i < n; i++)
  42. cout<<pr[n - 1].second[i]<<" ";
  43. return 0;
  44. }
Success #stdin #stdout 0s 4520KB
stdin
100
82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91
stdout
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 22 22 53 99 59 52 52 31 31 31 31 23 23 9 9 9 7 7 7 7 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3