WORMHOLES problem Week 2 DSA

Hi,

I was expecting a TLE for subtask 2 here, but the remainder(subtask 1) should have given AC. However, I got all AC in subtask 1 except one 1 case, where I got WA. Can someone please tell why am I getting this WA in subtask 1. My solution → CodeChef: Practical coding for everyone

Thanks,
Somesh

Try

2 1 1
1 10
4 6
3 
7

So the answer to this is 5 right? @everule1.
My code is also giving the same only. (7-3+1)

Undefined behaviour doing undefined things I guess.
I added one line, that tells you the value of vp. It becomes negative.

#include <bits/stdc++.h>

using namespace std;

// ************* All the typedefs *************************
typedef long long ll              ;    // long long
typedef string str                ;    // string

typedef list<int> lint            ;    // list of integers
typedef list<char> lchar          ;    // list of chars
typedef list<ll> llong            ;    // list of long long
typedef list<str> lstr            ;    // list of strings

typedef map<int, int> mii         ;    // map of integer-integer
typedef map<ll, ll> mll           ;    // map of long long-long long
typedef map<int, str> mis         ;    // map of integer-string
typedef map<ll, str> mls          ;    // map of long long-string
typedef map<str, int> msi         ;    // map of string-integer
typedef map<str, ll> msl          ;    // map of string-long long

typedef pair<int, int> pii        ;    // pair of integer-integer
typedef pair<ll, ll> pll          ;    // pair of long long-long long
typedef pair<int, str> pis        ;    // pair of integer-string
typedef pair<ll, str> pls         ;    // pair of long long-string
typedef pair<str, int> psi        ;    // pair of string-integer
typedef pair<str, ll> psl         ;    // pair of string-long long

typedef set<int> sint             ;    // set of integers
typedef set<char> schar           ;    // set of chars
typedef set<ll> slong             ;    // set of long long
typedef set<str> sstr             ;    // set of strings

typedef vector<int> vint          ;    // vector of integers
typedef vector<char> vchar        ;    // vector of chars
typedef vector<ll> vlong          ;    // vector of long long
typedef vector<str> vstr          ;    // vector of strings
// ************** Insert code here ************************

int main(void){

    ll n,x,y;
    cin >> n >> x >> y;

    vector<pll> contest;
    vlong v;
    vlong w;

    ll start_time, end_time, time, entry_time, exit_time;

    for(auto i=0;i<n;i++){
        cin >> start_time >> end_time;
        contest.push_back(make_pair(start_time, end_time));
    }

    for(auto i=0;i<x;i++){
        cin >> time;
        v.push_back(time);
    }

    for(auto i=0;i<y;i++){
        cin >> time;
        w.push_back(time);
    }

    sort(contest.begin(), contest.end());
    sort(v.begin(), v.end());
    sort(w.begin(), w.end());

    ll vp=0, wp=0;
    ll min_time = 1000001;

    for(auto i=0;i<n;i++){
        start_time = contest[i].first;
        end_time   = contest[i].second;

        // GET ENTRY TIME
        while(vp < x && v[vp]<start_time){
            vp++;
        }
        if(vp == x){
            vp--;
        }
        else if(v[vp] > start_time){
            vp--;
        }
        entry_time = v[vp];
        cout<<vp<<"\n";//This is the index you are accessing
        //It shouldn't be negative
        // GET EXIT TIME
        wp=0;
        while(wp < y && w[wp]<end_time){
            wp++;
        }
        if(wp == y){
            wp--;
        }
        exit_time = w[wp];

        // UPDATE MIN TIME
        if(entry_time <= start_time && exit_time >= end_time){
            time     = exit_time - entry_time + 1;
            min_time = time < min_time?time:min_time;
        }
    }

    cout << min_time;

    return 0;
}
1 Like