/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 540.0 KiB
#2 Wrong Answer 1ms 516.0 KiB

Code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> heights(n);

    for (int i = 0; i < n; i++) {
        cin >> heights[i];
    }

    // Identify the first segment of heights that is not non-decreasing
    for (int l = 0; l < n; l++) {
        for (int r = l + 1; r < min(n, l + k + 1); r++) {
            // Create a copy of the segment to sort
            vector<int> segment(heights.begin() + l, heights.begin() + r + 1);
            sort(segment.begin(), segment.end());

            // Check if the sorted segment fits into the original array
            bool valid = true;

            if (l > 0 && segment[0] < heights[l - 1]) {
                valid = false;  // Should be greater than or equal to the previous element
            }
            if (r < n - 1 && segment.back() > heights[r + 1]) {
                valid = false;  // Should be less than or equal to the next element
            }

            if (valid) {
                cout << "YES" << endl;
                cout << (l + 1) << " " << (r + 1) << endl;  // Output in 1-indexed format
                return 0;
            }
        }
    }

    // If we exhaust all options, return NO
    cout << "NO" << endl;
    return 0;
}

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 15:35:36
Judged At
2024-11-05 15:35:36
Judged By
Score
0
Total Time
1ms
Peak Memory
540.0 KiB