fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, t;
  8. cin >> n >> t;
  9. vector<int> a;
  10. vector<int> cnt(301, 0);
  11. for (int i = 0; i < n; ++i)
  12. {
  13. int v;
  14. cin >> v;
  15. a.push_back(v);
  16. cnt[v]++;
  17. }
  18.  
  19. for (int j = 0; j < min(n - 1, t - 1); ++j)
  20. {
  21. for (int i = 0; i < n; ++i)
  22. {
  23. a.push_back(a[i]);
  24. }
  25. }
  26.  
  27. int magic_mul = max(t - n, 0);
  28.  
  29. int best_res = 0;
  30. vector<int> res(301, 0);
  31. vector<int> res_used_magic(301, 0);
  32. for (int i = 0; i < a.size(); ++i)
  33. {
  34. int cur_res = 0;
  35. for (int j = 0; j <= a[i]; ++j)
  36. cur_res = max(cur_res, res[j] + 1);
  37.  
  38. int cur_res_with_magic = 0;
  39. for (int j = 0; j <= a[i]; ++j)
  40. {
  41. cur_res_with_magic = max(cur_res_with_magic, res_used_magic[j] + 1);
  42. cur_res_with_magic = max(cur_res_with_magic, res[j] + 1 + magic_mul * cnt[a[i]]);
  43. }
  44. res[a[i]] = cur_res;
  45. res_used_magic[a[i]] = cur_res_with_magic;
  46.  
  47. best_res = max(best_res, cur_res);
  48. best_res = max(best_res, cur_res_with_magic);
  49. }
  50.  
  51. cout << best_res;
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 3460KB
stdin
4 5
1 2 2 3
stdout
12