You are on page 1of 6

Name: Karan Sharma UID: 20BET1080

Section: DWWC-46 Subject: IT SKILLS


Domain Winning Camp Worksheet (Practice Questions)
Day 2
Question1. This is my score!

Question Link: https://www.codechef.com/problems/WATSCORE?tab=statement

Code:

#include <iostream>

using namespace std;

int main() {

// your code goes here

int t;

cin>>t;

while(t--){

int n;

cin>>n;

int a[n], b[n];

for(int i=0; i<n; i++){

cin>>a[i]>>b[i];

int sum = 0;

for(int i=0; i<9; i++){

int max = 0;
for(int j=0; j<n; j++){

if(i==a[j] && b[j]>max){

max=b[j];

sum+=max;

cout<<sum<<endl;

return 0;

Output:
Question 2. Temple Land

Question link: https://www.codechef.com/problems/TEMPLELA?tab=statement

Code:

#include <iostream>

using namespace std;

int find(int a[], int n){

int mid = (n+1)/2;

if( n%2 != 1 ) return 0;

if( a[0] != 1 || a[n-1] != 1 ) return 0;

for(int i=1; i<mid; i++){

if(a[i-1]+1 != a[i]) return 0;

for(int i=mid+1 ; i<n; i++){

if(a[i-1]-1 != a[i]) return 0;

return 1;

}
int main() {

// your code goes here

int t;

cin>>t;

while(t--){

int n;

cin>>n;

int a[n];

for(int i = 0; i<n; i++){

cin>>a[i];

int result = find(a, n);

if(result) cout<<"yes"<<endl;

else cout<<"no"<<endl;

return 0;

}Output:
Question 3. Roads In Chefland

Question link: https://www.codechef.com/problems/CROADS

Code:

#include <iostream>

using namespace std;

int main() {

// your code goes here

long long t,n,cost,v;

cin>>t;

while(t--){

cin>>n;

cost=0;

if(!(n&(n-1)))

cout<<"-1\n";

continue;

for(int i=1;i<=n;i<<=1)

v=(n-i)/(i<<1);

cost+=v*i +i;

cost--;
cout<<cost<<"\n";

return 0;

Output:

You might also like