PROBLEM LINK:Author: Vaibhav Tulsyan DIFFICULTY:CAKEWALK PREREQUISITES:Most basic programming PROBLEM:There are $N$ tasks numbered from $1$ to $N$ to perform. Two people, Xenny and Yana, have to complete all these tasks alternatingly. It means that either Xenny performs tasks with odd numbers and Yana with even numbers, or Xenny performs tasks with even numbers and Yana with odd numbers. These two ways are the only possibilities to fulfill the task. Moreover, we know that Xenny takes $X_i$ seconds to complete the $i$th task, while Yana takes $Y_i$ to do that. The goal of the problem is to compute the minimum possible time in which Xenny and Yana can complete all the tasks. QUICK EXPLANATION:Calculate the time needed to complete the tasks for each of two distinct ways of doing that and return the minimum of these times. EXPLANATION:The main observation is that since all the tasks have to performed alternatingly by Xenny and Yana, then there are only two distinct ways of completing all the tasks:
If we assume that for $i = 1, 2, \ldots, N$ $X[i]$ is the time for performing the $i$th task by Xenny and $Y[i]$ is the time for performing the $i$th task by Yana, then we can solve the problem by the following pseudocode:
Since in order to compute the time of completing the tasks for each of the two methods we need only to iterate once over all tasks, the overall time complexity of this solution is $O(N)$. AUTHOR'S AND TESTER'S SOLUTIONS:
This question is marked "community wiki".
asked 07 Mar '17, 18:43

@vayuhu Change the indexing in your code or make array of size n+1 this will get you can AC.In your code you have made array of n which will be from 0 to n1 and you are accessing 1 upto n elements.You are not able to access very first element of the array.Hope it helps :) Edit:Your AC solution Click here answered 19 Mar '17, 12:36

include<stdio.h>int main() { int t,n,i,z,w; scanf("%d",&t); while(t) { scanf("%d",&n); int a[n],z=0; int b[n],w=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); } for(i=1;i<=n;i++) { scanf("\n%d",&b[i]); } for(i=1;i<=n;i++) { if(i%2==0) { z+=a[i]; } else { z+=b[i]; } } for(I=1;i<=n;i++) { if(i%2==0) { w+=b[i]; } else { w+=a[i]; } } int sum=z<w?z:w; printf("%d",sum); } return 0; } / help me it's shoing rong answer / answered 19 Mar '17, 11:54

hi I need a little help codechef is not considering my code as correct answer but I have run is on ideone . com and its running perfectly there. Can you please tell me where am I wrong. include<iostream>using namespace std; int main() { int t,n,i; cin>>t; int s[2]={0,0}; if(t>=0) { cin>>n; int a[n],b[n]; for(int j=0;j<t;j++) {
} thanks answered 25 Mar '17, 23:06

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 t=sc.nextInt(); long n,s1=0,s2=0; long xi[]=new long[20000]; int i; while(t!=0) { t; n=sc.nextLong(); for(i=0;i<n;i++) {="" xi[i]="sc.nextLong();" if(i%2="=1)s1+=xi[i];" if(i%2="=0)s2+=xi[i];" }="" for(i="0;i<n;i++)" {="" xi[i]="sc.nextLong();" if(i%2="=1)s2+=xi[i];" if(i%2="=0)s1+=xi[i];" }="" if(s1="">s2)System.out.println(s2); else System.out.println(s1); } } } What is wrong with my code? answered 29 Mar '17, 10:43
