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

Audits for your project from HashEx

String theory

Lateral Movement using Excel.Application and DCOM

Introduction to Lambdas (Kotlin)

Hasura Data and Schema Management APIs

Announcing another set of GraphQL Fireside Chats: a Special Series of Online Events

Build The World’s Simplest ETL (Extract, Transform, Load) Pipeline in Ruby With Kiba

Loading A Large CSV File In SQL Server

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

Find smallest size substring which contains all characters of other string.

Java Dialog Boxes: How to Make Them

Head First Java(second edition)-Chapter 01: dive into A Quick Dip

Why does Immutability in Java matter?