Codechef : Problem name " Cost of Groceries " solution in C#

     =============================Problem Statement==========================

==============================Solution in C#=============================
using System;

public class Test
{
public static void Main()
{
    int t=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<t;i++){
    
    string[] array=Console.ReadLine().Split(' ');
    int N=Convert.ToInt32(array[0]);
    int X=Convert.ToInt32(array[1]);
    
    string[] array1=Console.ReadLine().Split(' ');//freshness
    string[] array2=Console.ReadLine().Split(' ');//cost of items
    
    int cost=0;
    for(int k=0; k<N; k++)
    {
       if(Convert.ToInt32(array1[k])>=X){
           cost=cost+Convert.ToInt32(array2[k]);
       } 
    }
    
    Console.WriteLine(cost);
}
}
}
================================Explanation==============================
As for each input of array1 we are checking if the freshness value is equal to or greater than threshold value X as per input
If the above condition is satisfied then for that index K we will fetch value from array2 and add the value to cost variable
Later we will display the cost which is summation of all calculation. 


Comments