Help me in solving TLG problem

My issue

My code

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n;
	std::cin >> n;
	int temp[n];
	for(int i=0;i<n;i++)
	{
	    int n,m;
	    cin>>n>>m;
	    temp[i]=n-m;
	}
	sort(temp, temp+n);
	if(abs(temp[0])>temp[n-1])std::cout << " "<< 2 <<abs(temp[0]) <<std::endl;
	else std::cout << 1 <<" "<< temp[n-1]<< std::endl;
}

Problem Link: TLG Problem - CodeChef

@pranto1610
correct code below
#include<bits/stdc++.h>
include
using namespace std;

int main() {
// your code goes here
int lead=0,maxdiff=0,display=0;
int n;
cin>>n;
int a[n],b[n];

for(int i=0;i<n;i++)
{
    cin>>a[i]>>b[i];
}
	for(int i=0;i<n;i++)
{
    lead+=a[i]-b[i];
    if(abs(lead)>maxdiff)
    {
        maxdiff=abs(lead);
        display=(lead>0)?1:2;
    }
}
	cout<<display<<" "<<maxdiff<<endl;

return 0;

}

1 Like