https://www.codechef.com/viewsolution/47096388
can someone please help me Only 3rd subtask is not passing…
hey i think you missed the case of multiple invigilator. if there is two invigilator in the time interval of 0 to 5 then 0 5 will be inputted twice in your pair and your code will add extra 5 minutes of invigilation. hope it will help.
I have tried all the test cases I could come up with but am still failing test case #1. I have read the editorial and my code seems to handle all three cases mentioned. Kindly help me figure out the issue. Thanks in advance!
Code ![]()
Please provide some test where it will fail.
Replacable Code
while(x<n+2 && count<k)
{
if(flag)
{
prev=ar[x-1].e;
}
long cur=ar[x].s;
if(prev<cur)
{
if(flag==false)
{
flag=true;
continue;
}
count+=cur-prev;
}
else if(prev>cur)
{
flag=false;
}
// System.out.println(count);
x++;
}
Why don’t you replace this entire thing with one for loop?
Initialise a variable free_time with 0.
For each i, 1 \le i \le (N + 1), free_time += (ar[i].s - ar[i - 1].end).
You know the reason why I took 1 to N + 1.
Now, check if free_time >= k. Output YES or NO based on this condition.
Edit: This will not work unless you merge Overlapping Intervals.
I did the same thing in the last for loop used count as variable
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--)
{
int n, g, tg;
cin >> n >> g >> tg;
vector<pair<int, int>> a(n);
for(int i=0; i<n; i++)
cin >> a[i].first >> a[i].second;
int safe[tg];
memset(safe, 0, sizeof(safe));
for(int i=0; i<n; i++)
{
int s = a[i].first, e = a[i].second;
for(int j=s; j<e; j++)
safe[j] = 1;
}
int counter = 0;
for(int i=0; i<tg; i++)
{
if(safe[i] == 0)
counter++;
}
(counter >= g) ? cout << "yes\n" : cout << "no\n";
}
return 0;
}
can anyone help !!!
You haven’t told us what problem you’re running into, yet 
Yes they do take overlapping intervals