fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. struct Line
  7. {
  8. int start{};
  9. int end{};
  10. int weight{};
  11. };
  12.  
  13. static const int size = 100;
  14.  
  15. int main()
  16. {
  17. std::ifstream fin{"input.txt"};
  18.  
  19. int N;
  20. fin >> N;
  21.  
  22. std::vector<Line> lines(size);
  23.  
  24. for (int i{}; i < N; i++)
  25. {
  26. int num;
  27. fin >> num;
  28. Line& line = lines[num - 1];
  29.  
  30. if (line.start == 0)
  31. line.start = i;
  32. line.end = i;
  33. line.weight++;
  34. }
  35.  
  36. fin.close();
  37.  
  38. std::sort(lines.begin(), lines.end(), [](const Line& a, const Line& b) {
  39. return b.start > a.start;
  40. });
  41.  
  42. std::vector<int> best(size);
  43. for (int i{}; i < size; i++)
  44. {
  45. Line& line = lines[i];
  46. best[i] = line.weight;
  47.  
  48. for (int j{}; j < i; j++)
  49. if (lines[j].end < line.start)
  50. best[i] = std::max(best[i], best[j] + line.weight);
  51. }
  52.  
  53. std::ofstream fout{"output.txt"};
  54. fout << *std::max_element(best.begin(), best.end());
  55. fout.close();
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty