Camp Or Not Codechef Solution

Camp Or Not Codechef Solution: The Petrozavodsk camp takes place in about one month. Jafar wants to participate in the camp, but guess what? His coach is Yalalovichik.

Yalalovichik is a legendary coach, famous in the history of competitive programming. However, he is only willing to send to the camp students who solve really hard problems on Timus. He started a marathon at the beginning of December. Initially, he said that people who solve 200 or more problems by the 31-st of December may go to the camp. Jafar made a schedule for the next month. For each day, he knows how many problems he is going to solve.

The problem is that Yalalovichik is a really moody coach — he may wake up tomorrow and change his decision about the deadline and the number of problems that must be solved by this deadline to qualify for the camp. Jafar has QQ such scenarios. Now he wants to know: in each scenario, if he does not change his problem solving schedule, will he go to the camp or not?


  • 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 a single integer DD – the number of days in Jafar’s schedule.
  • DD lines follow. For each ii (1≤i≤D1≤i≤D), the ii-th of these lines contains two space-separated integers didi and pipi denoting that Jafar will solve pipi problems on day didi.
  • The next line contains a single integer QQ denoting the number of scenarios Jafar considers.
  • QQ lines follow. For each ii (1≤i≤Q1≤i≤Q), the ii-th of these lines contains two space-separated integers deadideadi and reqireqi denoting a scenario where Yalaovichik decides that students who solve reqireqi problems by day deadideadi (inclusive) will go to the camp.


For each scenario, print a single line containing the string "Go Camp" if Jafar is going to the camp or "Go Sleep" otherwise (without quotes).


  • 1≤T≤1001≤T≤100
  • 1≤D≤311≤D≤31
  • 1≤di≤311≤di≤31 for each valid ii
  • 1≤pi≤1001≤pi≤100 for each valid ii
  • d1,d2,…,dDd1,d2,…,dD are pairwise distinct
  • 1≤Q≤1001≤Q≤100
  • 1≤deadi≤311≤deadi≤31 for each valid ii
  • 1≤reqi≤5,0001≤reqi≤5,000 for each valid ii

Sample Input 1 

10 5
14 4
31 1
9 2
15 7

Sample Output 1 

Go Sleep
Go Camp


Example case 1:

  • By the end of day 99, Jafar will not have any problem solved.
  • By the end of day 1515, Jafar will have 99 problems solved, which is enough to go to the camp, since he needs at least 77 problems.

Camp Or Not Codechef Solution in JAVA

import java.util.Scanner;
public class Main {
	static final int LIMIT = 31;
	public static void main(String[] args) {
		Scanner sc = new Scanner(;
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int D = sc.nextInt();
			int[] d = new int[D];
			int[] p = new int[D];
			for (int i = 0; i < D; i++) {
				d[i] = sc.nextInt();
				p[i] = sc.nextInt();
			int Q = sc.nextInt();
			int[] dead = new int[Q];
			int[] req = new int[Q];
			for (int i = 0; i < Q; i++) {
				dead[i] = sc.nextInt();
				req[i] = sc.nextInt();
			System.out.print(solve(d, p, dead, req));
	static String solve(int[] d, int[] p, int[] dead, int[] req) {
		int[] problems = new int[LIMIT + 1];
		for (int i = 0; i < d.length; i++) {
			problems[d[i]] = p[i];
		int sum = 0;
		int[] sums = new int[problems.length];
		for (int i = 0; i < sums.length; i++) {
			sum += problems[i];
			sums[i] = sum;
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < dead.length; i++) {
			result.append((req[i] <= sums[dead[i]]) ? "Go Camp" : "Go Sleep").append("\n");
		return result.toString();

Camp Or Not Codechef Solution in CPP

#include <bits/stdc++.h>
using namespace std;
int main()
    int t;
        int d, arr[31] = {0};
            int day, nQues;
            arr[day-1] = nQues;
        int temp =  arr[0];
        for(int i =1; i<31; i++){
            temp = arr[i];
        int q;
            int dead, nReq;
            if(arr[dead-1]>=nReq)cout<<"Go Camp\n";
            else cout<<"Go Sleep\n";
    return 0;

Camp Or Not CodeChef Solution in Python

for _ in range(int(input())):
    day = int(input())
    xd = []
    temp_num = 0
    temp_day = 1
    for i in range(day):
        d, p = map(int, input().split())
        xd += [temp_num] * (d-temp_day)
        temp_day = d
        temp_num += p
    xd += [temp_num] * (32 - temp_day)
    q = int(input())
    for i in range(q):
        dead, req = map(int, input().split())
        if xd[dead-1] >= req: print('Go Camp')
        else: print('Go Sleep')

Disclaimer: The above Problem (Camp Or Not) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring

Leave a Comment