My issue
can any one explain output for this problem.
My code
#include <iostream>
using namespace std;
int main() {
// your code goes here
return 0;
}
Problem Link: TLG Problem - CodeChef
can any one explain output for this problem.
#include <iostream>
using namespace std;
int main() {
// your code goes here
return 0;
}
Problem Link: TLG Problem - CodeChef
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] p1 = new int[n];
int[] p2 = new int[n];
int[] res = new int[n];
int[] lead = new int[n];
for(int i = 0; i < p1.length;i++){
p1[i] = in.nextInt();
p2[i] = in.nextInt();
}
int sum1 = 0,sum2 = 0;
for(int i = 0; i < p1.length;i++){
sum1 +=p1[i];
sum2 +=p2[i];
p1[i] = sum1;
p2[i] = sum2;
}
for(int i = 0; i < p1.length;i++){
if(p1[i]>p2[i]){
res[i] = p1[i] - p2[i];
lead[i] = 1;
}else if(p1[i]<p2[i]){
res[i] = p2[i] - p1[i];
lead[i] = 2;
}
}
int max = 0;int l = 0;
for(int x = 0; x < res.length; x++){
if(res[x]>max){
max = res[x];
l = lead[x];
}
}
System.out.print(l +" "+ max);
}
}
Here is my approach in java program