Chef And Work (With Solution)— August COOKOFF 2020 Codechef

Codechef Logo

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first line of each test case contains two space-separated integers NN and KK.
  • The second line contains NN space-separated integers W1,W2,…,WNW1,W2,…,WN.

Output

Constraints

  • 1≤T≤1001≤T≤100
  • 1≤N,K≤1031≤N,K≤103
  • 1≤Wi≤1031≤Wi≤103 for each valid ii

Example Input

4
1 1
2
2 4
1 1
3 6
3 4 2
3 6
3 4 3

Example Output

-1
1
2
3

Explanation

/* 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
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int n=0,k=0;

while(t-- >0){
n = sc.nextInt();
k = sc.nextInt();
int total=0,moves=1;
int arr[] = new int [n];
for(int i=0;i<n;i++)
arr[i] = sc.nextInt();

for(int i=0;i<n;i++){
if(arr[i]>k){
moves=-1;
break;
}
else if(total+arr[i]<=k){
total= total+arr[i];
}
else{
moves++;
total = arr[i];
}
}
System.out.println(moves);

}
}
}

--

--

--

Software Developer ,currently pursuing B.Tech in Information Technology. Electronic Dance Music is love.Also like all phone related technologies

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Maven : The favorite Java Build Tool

How to use Autorize

3 Insane Secret Weapons for Python

The journey to a cheap(er) infrastructure

Record media duration and send it to Firebase Analytics

My journeyto self realisation

Implementing a Hash Table in Ruby

WP Rocket: Is It Worth the $49?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anubhav Mishra

Anubhav Mishra

Software Developer ,currently pursuing B.Tech in Information Technology. Electronic Dance Music is love.Also like all phone related technologies

More from Medium

Chapter 7 -Inheritance and Polymorphism

Let’s talk about head first Java

Numbering System edge cases of Java