/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 432.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 712.0 KiB
#6 Accepted 1ms 552.0 KiB
#7 Accepted 1ms 428.0 KiB
#8 Accepted 1ms 532.0 KiB
#9 Accepted 1ms 532.0 KiB
#10 Accepted 1ms 532.0 KiB
#11 Accepted 1ms 532.0 KiB
#12 Accepted 1ms 532.0 KiB
#13 Accepted 1ms 532.0 KiB
#14 Accepted 1ms 480.0 KiB
#15 Accepted 1ms 324.0 KiB
#16 Accepted 1ms 544.0 KiB
#17 Accepted 1ms 532.0 KiB
#18 Accepted 1ms 344.0 KiB
#19 Accepted 1ms 532.0 KiB
#20 Accepted 1ms 520.0 KiB
#21 Accepted 2ms 436.0 KiB
#22 Accepted 35ms 1.77 MiB
#23 Accepted 15ms 1.77 MiB
#24 Accepted 17ms 2.27 MiB
#25 Accepted 32ms 3.246 MiB
#26 Accepted 11ms 1.77 MiB
#27 Accepted 3ms 788.0 KiB
#28 Accepted 17ms 1.77 MiB
#29 Accepted 41ms 2.02 MiB
#30 Accepted 23ms 3.062 MiB
#31 Accepted 32ms 2.52 MiB
#32 Accepted 24ms 3.27 MiB
#33 Accepted 19ms 2.77 MiB
#34 Accepted 20ms 2.312 MiB
#35 Accepted 52ms 3.602 MiB

Code

/*
 *Copyright (c) Swadheen Islam Robi (SIR01)
 *Created on Tue Nov 05 2024 9:14:06 PM
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pie 2*(acos(0.0))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define endl "\n"
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);

void sir2()
{
    // int y
    ll n,k; cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0; i<n; i++)cin>>a[i];

    ll sc =0;
    ll cnt=1;
    ll st, en;
    //bool ok = false;
    ll chk =0;
    for(ll i=0; i<n-1; i++)
    {
        if(a[i]>a[i+1]){
            sc++;
            ll key = a[i];
            if(i !=0) chk = a[i-1];
            
            st = i;
            i++;
            
            while(1)
            {
                if(key>a[i]){
                    cnt++;
                en = i;
                //if(a[i]<chk) ok = true;
                i++;
                }
                else {
                    i--;
                    break;
                }
                
            }

        }
    }
    if(sc>1 || cnt>k || cnt==1) cout<<"NO"<<endl;
    else{
        cout<<"YES"<<endl;
        cout<<st+1<<" "<<en+1<<endl;
        //cout<<sc<<" "<<cnt;
    }
    
}
void sir()
{
    ll n, k; cin>>n>>k;
    vector<ll>a(n), b(n);
    for(ll i=0; i<n; i++)
    {
        cin>>a[i];
        b[i] = a[i];
    }
    srt(b);
    ll st=0,end=0;
    for(ll i=0; i<n; i++)
    {
        if(a[i] != b[i]) 
        {st = i+1;
         break;}
    }
    for(ll i=n-1; i>=0; i--)
    {
        if(a[i] != b[i]) {end = i+1; break;}
    }
    
    if(st){
        if(end-st+1<=k){
        cout<<"YES"<<endl;
        cout<<st<<" "<<end<<endl;
        return;
        }
    }
    cout<<"NO"<<endl;
}

int main() {
    ALLAHU_AKBAR

    ll t = 1;
    //cin>>t;
    while(t--)
    {
        sir();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1120 Stairway to the Skyline
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 17:24:23
Judged At
2024-11-05 17:24:23
Judged By
Score
100
Total Time
52ms
Peak Memory
3.602 MiB