PLPROCESS - Editorial

Can be easily done by Kadane’s algorithm !

[Easy Solution](https://www.codechef.com/viewsolution/59297791)

Hello sir @notsoloud can you please give the test case 2 for PLPROCESS mine solution passed all of em but test case 2
thanks

1 Like

https://www.codechef.com/viewsolution/59274099

passed all the testcase, but somehow could clear the 2nd testcase. Where exactly did I go wrong?

Your approach is incorrect.
You have to assign a prefix of the processes to the first processor.

Consider the test case:

3
3 4 5

Your code gives output max(3+5,4)=8. However, the correct output is max(3+4,5)=7.

https://www.codechef.com/viewsolution/59388658
Why am I getting wrong answer on test 3?

solution: I solved the problem, I had to give the initial value to accumulate as 0ll, the accumulate function did not automatically type cast the sum to long long

Can anyone please tell me where is my code failing?
It was getting WA on test case 3.

Code

You’ve shared wrong link, open your submission then share that link.

1 Like

thanks

My solution is getting failed for test case 2 . Can anybody tell me what is wrong in my solution?

https://www.codechef.com/viewsolution/59290153


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		int t = Integer.parseInt(br.readLine());
		while(t-->0) {
			int n = Integer.parseInt(br.readLine());
			String[] s = br.readLine().split(" ");
			if(n == 1) {
				bw.write(s[0]+"\n");
			}
			else {
				int[] a = new int[n];
				long[] freq = new long[n];
				a[0] = Integer.parseInt(s[0]);
				freq[0] = a[0];
				for(int i=1;i<n;i++) {
					a[i] = Integer.parseInt(s[i]);
					freq[i] = a[i] + freq[i-1];
				}
				//System.out.println(Arrays.toString(freq));
				long min = Integer.MAX_VALUE;
				long max = Integer.MIN_VALUE;
				
				for(int i=0;i<n;i++) {
					max = Math.max(freq[n-1] - freq[i],freq[i]);
					min = Math.min(max, min);
				}
				bw.write(min+"\n");
				//boolean b = test();
			}
			
		} 
		bw.flush();
		bw.close();
		br.close();
		
	}

}

WA on Test case 3 ?
Anyone know the reason ?

Really a very great question. Need more such questions.

1 Like

check for
3
4 17 1
by this method ans will be 21 but ans should be 18

hey, bro, u solve this question?I also solve exactly like your solution.

test case 2 failing
help required

solution below mentioned

/* 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
{
Scanner sc=new Scanner(System.in);
int o;
o=sc.nextInt();
while(o–!=0)
{
int a[],b,n;
long sum1=0,sum2=0;
n=sc.nextInt();
a=new int[n];
for(b=0;b<n;b++)
{
a[b]=sc.nextInt();
}
Arrays.sort(a);
sum1=a[n-1];
for(b=n-2;b>=0;b–)
{
if(sum1>sum2)
sum2=sum2+a[b];
else
sum1=sum1+a[b];
}
// System.out.println(sum1+" "+sum2);
System.out.println(Math.max(sum1,sum2));

}}

}
ANYONE PLZ HELP

1 Like

Here min = 2^{31} - 1, but if input is array of length 10^5 with all elements 10^5, our answer will be 5 * 10^9 > min and hence output will be wrong.

1 Like

I understand that you are trying to minimize the difference between the two sums and then print the maximum one. But, problem specifies that we have to choose a prefix and give that to one processor and the rest to other processor. Hence, we do not have the freedom to shuffle them as we wish.

If I misunderstood your intentions please elaborate on what are you trying to do here :

if(sum1>sum2)
sum2=sum2+a[b];
else
sum1=sum1+a[b];
}
// System.out.println(sum1+" "+sum2);
System.out.println(Math.max(sum1,sum2));

}}

sorry for the touble i miunderstood the problem