/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 2ms 328.0 KiB
#4 Accepted 2ms 540.0 KiB
#5 Accepted 2ms 520.0 KiB
#6 Accepted 2ms 484.0 KiB
#7 Accepted 3ms 484.0 KiB
#8 Accepted 2ms 772.0 KiB
#9 Accepted 2ms 772.0 KiB
#10 Accepted 2ms 532.0 KiB
#11 Accepted 2ms 412.0 KiB
#12 Accepted 2ms 536.0 KiB
#13 Accepted 2ms 540.0 KiB
#14 Accepted 2ms 772.0 KiB
#15 Accepted 2ms 488.0 KiB
#16 Accepted 2ms 516.0 KiB
#17 Accepted 3ms 532.0 KiB
#18 Accepted 2ms 480.0 KiB
#19 Accepted 3ms 488.0 KiB
#20 Accepted 2ms 536.0 KiB
#21 Accepted 4ms 656.0 KiB
#22 Accepted 24ms 1.664 MiB
#23 Accepted 25ms 1.766 MiB
#24 Accepted 29ms 2.188 MiB
#25 Accepted 58ms 3.188 MiB
#26 Accepted 20ms 1.816 MiB
#27 Accepted 5ms 600.0 KiB
#28 Accepted 27ms 1.762 MiB
#29 Accepted 34ms 2.09 MiB
#30 Accepted 40ms 3.152 MiB
#31 Accepted 44ms 2.629 MiB
#32 Accepted 44ms 3.219 MiB
#33 Accepted 36ms 2.695 MiB
#34 Accepted 38ms 2.18 MiB
#35 Accepted 44ms 3.578 MiB

Code

#include <bits/stdc++.h>
#define int long long
#define sqrtl(x) sqrt(x)
using namespace std;

namespace solve {
  namespace test_case {
    void main() {
      int n, k; cin >> n >> k;
      vector<int> a(n);
      for (auto &x: a) cin >> x;
      int i (0), j(n - 1); 
      if (is_sorted(a.begin(), a.end())) {
        cout << "YES\n" << 0 << ' ' << n << '\n';
      } else {
        auto b = vector(a);
        sort(b.begin(), b.end());
        int i (0), j (n - 1);
        for (; i < n; i++) {
          if (b[i] != a[i]) break;
        }
        for (; j >= 0; j--) {
          if (b[j] != a[j]) break;
        }
        if (j - i + 1 <= k) cout << "YES\n" << i + 1 << ' ' << j + 1 << '\n';
        else cout << "NO\n";
      }
    }
  }

  void main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t (1); // cin >> t; 
    while (t--) {
      test_case::main();
    }
  }
}

signed main() { solve::main(); }

Information

Submit By
Type
Submission
Problem
P1120 Stairway to the Skyline
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 16:01:06
Judged At
2024-11-11 02:28:54
Judged By
Score
100
Total Time
58ms
Peak Memory
3.578 MiB