### Problem Statement :

```You have a long list of tasks that you need to do today. To accomplish task  you need  minutes, and the deadline for this task is . You need not complete a task at a stretch. You can complete a part of it, switch to another task, and then switch back.

You've realized that it might not be possible to complete all the tasks by their deadline. So you decide to do them in such a manner that the maximum amount by which a task's completion time overshoots its deadline is minimized.

Input Format

The first line contains the number of tasks, . Each of the next  lines contains two integers,  and .

Output Format

Output  lines. The  line contains the value of the maximum amount by which a task's completion time overshoots its deadline, when the first  tasks on your list are scheduled optimally. See the sample input for clarification.```

### Solution :

```                            ```Solution in C :

In  C  :

#include <stdio.h>
#include <stdlib.h>

int l_cost, cost, r_cost, total_cost;
int time, max_over;
};

int cur_over, max_over;
max_over = t->cost - t->time;
if (t->l) {
t->l_cost = t->l->total_cost;
max_over += t->l_cost;
cur_over = t->l->max_over;
if (cur_over > max_over) max_over = cur_over;
} else {
t->l_cost = 0;
}
if (t->r) {
t->r_cost = t->r->total_cost;
cur_over = t->r->max_over + t->l_cost + t->cost;
if (cur_over > max_over) max_over = cur_over;
} else {
t->r_cost = 0;
}
t->total_cost = t->l_cost + t->cost + t->r_cost;
t->max_over = max_over;
}

t->l = t->r = 0;
t->time = time;
t->cost = cost;
return t;
}

if (t) {
if (recur) {
}
free(t);
}
}

} else {
*tree = t;
}
}

int main(void) {
for (i = 0; i < num_tasks; ++i) {
printf("%d\n", tree->max_over >= 0 ? tree->max_over : 0);
}
return 0;
}```
```

```                        ```Solution in C++ :

In  C++  :

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cctype>
#include <numeric>
#include <queue>
#include <iostream>
#include <iomanip>
#include <sstream>
#define FOR(i,s,e) for(int i=(s);i<(int)(e);i++)
#define FOE(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define ALL(x) (x).begin(), (x).end()
#define CLR(s) memset(s,0,sizeof(s))
#define PB push_back
#define EARLY if(found)return;
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
#define x first
#define y second

#define L(p) ((p)*2+1)
#define R(p) ((p)*2+2)

const int N = 203600*4;
const int INF = 2036000;

int mx = 0;
int node[N];    // store minimum
bool up[N];             // updated, not yet spread
int  ex[N];             // extra to add

void Init() {
CLR(node);
CLR(ex);
CLR(up);
}

void Upd(int p, int a) {
up[p]    = 1;
ex[p]   += a;
node[p] += a;
}

void Push(int p) {
//      if (up[p]) {
// Propagate the flipping effects to children...
//              printf("Push %d to child...\n", ex[p], p);
Upd(L(p), ex[p]);
Upd(R(p), ex[p]);
up[p] = ex[p] = 0;      // reset. . .
//      }
return;
}

void Upd(int p, int s, int e, int u, int v, int a) {    // [s, e)
mx = max(mx, p);

u = max(u, s);
v = min(v, e);
if (u >= v) return;
if (u == s && v == e) {
node[p] += a;
ex[p]   += a;
up[p]    = 1;
} else {
Push(p);

int md = s+e>>1;
Upd(L(p),  s, md, u, v, a);
Upd(R(p), md,  e, u, v, a);
node[p] = max(node[L(p)], node[R(p)]);
}
//      printf("On Upd [%d %d) + %d: [%d %d) = %d\n", u, v, a, s, e, node[p]);
}

// range max
int Que(int p, int s, int e, int u, int v) {
//      printf("At [%d, %d): ", s, e);
Push(p);

//      if (u>=e || v<=s) return INF;
u = max(u, s);
v = min(v, e);
if (u >= v) return -INF;

int ret;

if (u==s && v==e) {
ret = node[p];
} else {
int md = s+e>>1;
int t1 = Que(L(p), s, md, u, v);
int t2 = Que(R(p), md, e, u, v);
ret = max(t1, t2);
}
//      printf("Ret[%d, %d) = %d\n", s, e, ret);
return ret;
}

int u;

void Trace() {
FOR(i,0,u) {
printf("[%d] = %d\n", i, Que(0, 0, u, i, u));
}
}

int main() {
int n = 103600;

//n = 16;
u = 1;
while (u<n) u<<=1;

Init();

FOR(i,0,u) {
//              printf("[%d %d)\n", i, u);
Upd(0, 0, u, i, u, -1);
}
//Trace();

int mx = 0;

int T; scanf("%d", &T);
while (T--) {
int d, m;
scanf("%d%d", &d, &m);
mx = max(mx, d);
Upd(0, 0, u, d-1, u, m);
int ans = Que(0, 0, u, 0, mx);
if (ans < 0) ans = 0;
printf("%d\n", ans);
}

return 0;
}```
```

```                        ```Solution in Java :

In  Java :

import java.util.*;
import java.io.*;

class Solution
{
BufferedWriter out;
StringTokenizer token;

int[] ST;

void update(int s,int e,int x,int a,int b,int v)
{
if(s > b || e < a)return;
if(s >= a && e <= b)
{
return;
}
update(s,(s+e)/2,2*x+1,a,b,v);
update((s+e)/2+1,e,2*x+2,a,b,v);
}

void build(int s,int e,int x)
{
if(s==e)
{
ST[x] = -s;
return;
}
build(s,(s+e)/2,2*x+1);
build((s+e)/2+1,e,2*x+2);
ST[x] = Math.max(ST[2*x+1],ST[2*x+2]);
}

int query(int s,int e,int x,int a,int b)
{
if(s > b || e < a)return 0;
if(s >= a && e <= b)
{
}
int first = query(s,(s+e)/2,2*x+1,a,b);
int second = query((s+e)/2+1,e,2*x+2,a,b);
return Math.max(first,second);
}

void solve() throws IOException
{
out = new BufferedWriter(new OutputStreamWriter(System.out));
int T = nextInt();
int maxD = 4*(100000+3);
ST = new int[maxD];
build(0,100000,0);
for(int t = 0; t < T; t++)
{
int D = nextInt();
int M = nextInt();
update(0,100000,0,D,100000,M);
out.write(""+query(0,100000,0,0,100000));
out.newLine();
}
out.flush();
}

int nextInt() throws IOException
{
if(token == null || !token.hasMoreTokens())
return Integer.parseInt(token.nextToken());
}

Long nextLong() throws IOException
{
if(token == null || !token.hasMoreTokens())
return Long.parseLong(token.nextToken());
}

String next() throws IOException
{
if(token == null || !token.hasMoreTokens())
}

public static void main(String[] args) throws Exception
{
new Solution().solve();
}
}```
```

```                        ```Solution in Python :

In  Python3  :

def returnIndex(array,number):
if not array:
return None
if len(array) == 1:
if number > array[0]:
return 0
else:
return None

si = 0
ei = len(array)-1
return binarySearch(array,number,si,ei)

def binarySearch(array,number,si,ei):
if si==ei:
if number >= array[si]:
return si
else:
return si-1
else:
middle = (ei-si)//2 +si
if number > array[middle]:
return binarySearch(array,number,middle+1,ei)
elif number < array[middle]:
return binarySearch(array,number,si,middle)
else:
return middle

array.append(i+length)
minLeft = minutes
if index != None:
while index >=0 and minLeft >0:
array.pop(index)
index -= 1
minLeft -=1

while minLeft >0 and array and array[0] < deadline:
array.pop(0)
minLeft -=1
late += minLeft
return late,length

if __name__ == '__main__':

n = int(input().strip())

time = 0
length = 0

nl = []
late = 0
for op in range(n):
job = input().split(' ')
print(late)```
```

## Tree Coordinates

We consider metric space to be a pair, , where is a set and such that the following conditions hold: where is the distance between points and . Let's define the product of two metric spaces, , to be such that: , where , . So, it follows logically that is also a metric space. We then define squared metric space, , to be the product of a metric space multiplied with itself: . For

## Array Pairs

Consider an array of n integers, A = [ a1, a2, . . . . an] . Find and print the total number of (i , j) pairs such that ai * aj <= max(ai, ai+1, . . . aj) where i < j. Input Format The first line contains an integer, n , denoting the number of elements in the array. The second line consists of n space-separated integers describing the respective values of a1, a2 , . . . an .

## Self Balancing Tree

An AVL tree (Georgy Adelson-Velsky and Landis' tree, named after the inventors) is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. We define balance factor for each node as : balanceFactor = height(left subtree) - height(righ

## Array and simple queries

Given two numbers N and M. N indicates the number of elements in the array A[](1-indexed) and M indicates number of queries. You need to perform two types of queries on the array A[] . You are given queries. Queries can be of two types, type 1 and type 2. Type 1 queries are represented as 1 i j : Modify the given array by removing elements from i to j and adding them to the front. Ty