/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 300.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Wrong Answer 1ms 452.0 KiB
#7 Wrong Answer 1ms 532.0 KiB

Code


#include <bits/stdc++.h>

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];
    }

   
    vector<int> violations;

    
    for (int i = 0; i < n - 1; i++) {
        if (heights[i] > heights[i + 1]) {
            violations.push_back(i);
        }
    }

    
    if (violations.empty()) {
        cout << "NO" << endl;
        return 0;
    }

    
    for (int i = 0; i < violations.size(); i++) {
        // We are looking at the current violation
        int left = violations[i];
        int right = left + 1;


        while (right < n && right - left + 1 <= k) {
            // Check if we can reorder this segment
            vector<int> segment;
            for (int j = left; j <= right; j++) {
                segment.push_back(heights[j]);
            }
            // Sort the segment
            sort(segment.begin(), segment.end());

            
            bool fits = true;
            if (left > 0 && segment[0] < heights[left - 1]) {
                fits = false;  
            }
            if (right < n - 1 && segment.back() > heights[right + 1]) {
                fits = false; 
            }

            if (fits) {
                // Found a valid segment
                cout << "YES" << endl;
                cout << left + 1 << " " << right + 1 << endl; 
                return 0;
            }
            right++; 
        }
    }

    
    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:33:01
Judged At
2024-11-05 15:33:01
Judged By
Score
12
Total Time
1ms
Peak Memory
532.0 KiB