/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 436.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 488.0 KiB
#6 Accepted 1ms 324.0 KiB
#7 Accepted 1ms 480.0 KiB
#8 Accepted 1ms 364.0 KiB
#9 Accepted 1ms 320.0 KiB
#10 Accepted 1ms 480.0 KiB
#11 Accepted 1ms 324.0 KiB
#12 Accepted 1ms 540.0 KiB
#13 Accepted 1ms 344.0 KiB
#14 Accepted 1ms 324.0 KiB
#15 Accepted 1ms 508.0 KiB
#16 Accepted 1ms 484.0 KiB
#17 Accepted 1ms 324.0 KiB
#18 Accepted 1ms 324.0 KiB
#19 Accepted 1ms 396.0 KiB
#20 Accepted 1ms 324.0 KiB
#21 Accepted 2ms 580.0 KiB
#22 Accepted 16ms 1.566 MiB
#23 Accepted 16ms 1.812 MiB
#24 Accepted 17ms 2.316 MiB
#25 Accepted 32ms 3.188 MiB
#26 Accepted 11ms 1.812 MiB
#27 Accepted 3ms 696.0 KiB
#28 Accepted 18ms 1.77 MiB
#29 Accepted 18ms 2.023 MiB
#30 Accepted 22ms 3.27 MiB
#31 Accepted 25ms 2.629 MiB
#32 Accepted 25ms 3.316 MiB
#33 Accepted 19ms 2.816 MiB
#34 Accepted 22ms 2.543 MiB
#35 Accepted 24ms 3.484 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-11 02:25:58
Judged By
Score
100
Total Time
32ms
Peak Memory
3.484 MiB