fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct subInfo {
  8. int lastNum = 0;
  9. int length = 0;
  10. };
  11.  
  12. int main(void) {
  13. int N;
  14. cin >> N;
  15.  
  16. vector<int> A(N);
  17. for (int i=0; i<N; i++) {
  18. cin >> A[i];
  19. }
  20.  
  21. int answer = 1;
  22. vector<subInfo> data;
  23.  
  24. for (int i=0; i<N; i++) {
  25. subInfo* pMaxSI = nullptr;
  26. for (subInfo& si: data) {
  27. if (si.lastNum < A[i] && (pMaxSI == nullptr || pMaxSI->length < si.length)) {
  28. pMaxSI = &si;
  29. }
  30. }
  31.  
  32. if(pMaxSI == nullptr) {
  33. data.push_back(subInfo{A[i], 1});
  34. cout << A[i] << ' ' << 1 << endl;
  35. }
  36. else {
  37. pMaxSI->lastNum = A[i];
  38. pMaxSI->length++;
  39. cout << pMaxSI->lastNum << ' ' << pMaxSI->length << endl;
  40. answer = max(answer, pMaxSI->length);
  41. }
  42. }
  43.  
  44. cout << data.size() << endl;
  45. cout << answer;
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 5424KB
stdin
8
90 80 70 60 50 40 30 20
stdout
90 1
80 1
70 1
60 1
50 1
40 1
30 1
20 1
8
1