or multiset can be used, instead of set

Use S.erase(*S.rbegin()) in place of S.erase(S.rbegin()). Here we need to dereference the value pointed by the iterator at rbegin().

If u r using --s.end(), the decrement operator automatically dereference it for us, so no need of *.

Can anyone tell me whats wrong with my code (FENCE Question). Iām getting error RE(SIGSEGV).

#include<stdio.h>

#include<stdlib.h>

int main(void){

int t;

scanf("%d",&t);

while(tā){

int N,M;

int K,X[1000]={0},Y[1000]={0},a=1,b,i=1,j=1,ans=0,i1;

scanf("%d %d %d",&N,&M,&K);

for(i1=1;i1<=K;i1++){

scanf("%d %d",&X[i1],&Y[i1]);

}

while(i<=K){

if(X[i]+1==X[j]&&Y[i]==Y[j]){

ans-=1;

j++;

}

if(X[i]==X[j]&&Y[i]+1==Y[j]){

ans-=1;

j++;

}

if(X[i]-1==X[j]&&Y[i]==Y[j]){

ans-=1;

j++;

}

if(X[i]==X[j]&&Y[i]-1==Y[j]){

ans-=1;

j++;

}

if(j==K+1){

j=1;

i++;

ans+=4;

}

else{

j++;

}

}

printf("%d\n",ans);

}

return 0;

}

@sidhant007 Can you please help me with the solution of the last problem of the STL question in DSA learning series. Why one of my test case is giving TLE? Please help !!

Link to the question

https://www.codechef.com/LRNDSA03/problems/SUBPRNJL

Link to my solution

what if A={1,2,3,4,5} B={1,2,2 ,3,5} in this case if you take max from a which is at index 4 and you will make pair with B, then it will produce duplicate sum because B has duplicates

ok I got it, I didnāt read that A and B are pairwise distinct

I was solving this question with my submission being code, I am not able to identify what is causing TLE for the 3rd test case of the 2 nd subtask , I cross-checked it with other solutions as well, can someone help me identify the mistake.

@sidhant007 ?

Hey, i also have the same problem. did your problem gave a complete ac?

PBDS didnāt. I used a different approach for 100 pts.

thanks for replying

For DPAIRS, if I solve according to hints the solution is accepted but suppose If have repeated numbers in A, B i.e(A=1,2,2,3 B=1,7,8) A1+B2<A2+B2 is wrong. Anything I might be missing?

Python programmers, Iāve been having TLE error for the EXUNC problem. Iāve tried looking for other successful submissions but almost all of them TLE errors for the second sub-task.

Hereās my code. Is there any way to improve upon it and make it pass the second subtask?

```
n, q = map(int, input().split())
l = list(map(int, input().split()))
s = {1}
prev = l[0]
for i in range(1, n):
if l[i] % prev == 0:
pass
else:
s.add(i+1)
prev = l[i]
for _ in range(q):
temp = list(map(int, input().split()))
if len(temp) == 3:
i = temp[1]
num = temp[2]
s.add(i)
s.add(i+1)
if i!=1 and num % l[i-2] == 0:
s.discard(i)
if i!= n and l[i] % num == 0:
s.discard(i+1)
l[i-1] = num
elif len(temp) == 2:
req = temp[1]
while req > 0:
if req in s:
print(req)
break
req -= 1
```

Hi guys,

I am getting Wrong_Answer for this solution of Save Konoha. Can someone please point what is wrong here:

```
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
try {
Scanner input = new Scanner(System.in);
int testCases = Integer.parseInt(input.nextLine());
while (testCases-- > 0) {
String[] input1 = input.nextLine().split(" ");
int N = Integer.parseInt(input1[0]), Z = Integer.parseInt(input1[1]);
String[] powers = input.nextLine().split(" ");
// max-heap
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
for (int i = 0; i < N; i++)
pq.offer(Integer.parseInt(powers[i]));
int hits = 0, pow = 0;
while (Z > 0 && !pq.isEmpty()) {
pow = pq.poll();
Z -= pow;
if (pow/2 != 0) pq.offer(pow/2);
hits++;
}
if (Z > 0)
System.out.print("Evacuate");
else
System.out.println(hits);
}
} catch (Exception e) {
e.printStackTrace();
}
} // main
}
```

Thanks!