/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 516.0 KiB
#3 Accepted 1ms 584.0 KiB
#4 Accepted 1ms 584.0 KiB
#5 Accepted 1ms 540.0 KiB
#6 Accepted 2ms 344.0 KiB
#7 Accepted 1ms 332.0 KiB
#8 Accepted 1ms 540.0 KiB
#9 Accepted 2ms 508.0 KiB
#10 Accepted 1ms 572.0 KiB
#11 Accepted 1ms 540.0 KiB
#12 Accepted 1ms 332.0 KiB
#13 Accepted 2ms 524.0 KiB
#14 Accepted 1ms 540.0 KiB
#15 Accepted 1ms 540.0 KiB
#16 Accepted 1ms 772.0 KiB
#17 Accepted 1ms 516.0 KiB
#18 Accepted 1ms 540.0 KiB
#19 Accepted 1ms 612.0 KiB
#20 Accepted 1ms 540.0 KiB
#21 Accepted 2ms 540.0 KiB
#22 Accepted 15ms 1.77 MiB
#23 Accepted 16ms 1.945 MiB
#24 Accepted 17ms 2.312 MiB
#25 Accepted 32ms 3.02 MiB
#26 Accepted 11ms 1.934 MiB
#27 Accepted 3ms 796.0 KiB
#28 Accepted 17ms 1.816 MiB
#29 Accepted 19ms 2.09 MiB
#30 Accepted 23ms 3.152 MiB
#31 Accepted 26ms 2.52 MiB
#32 Accepted 25ms 3.27 MiB
#33 Accepted 25ms 2.688 MiB
#34 Accepted 22ms 2.102 MiB
#35 Accepted 24ms 3.754 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-05 16:01:06
Judged By
Score
100
Total Time
32ms
Peak Memory
3.754 MiB