Bishu Game

QUESTION

Bishu went to fight for Coding Club. There were N soldiers with various powers. There will be Q rounds to fight and in each round Bishu’s power will be varied. With power M, Bishu can kill all the soldiers whose power is less than or equal to M(<=M). After each round, All the soldiers who are dead in previous round will reborn.Such that in each round there will be N soldiers to fight. As Bishu is weak in mathematics, help him to count the number of soldiers that he can kill in each round and total sum of their powers.\n\nExplanation\nIn first round bhishu power is 3\n\nSo there are 3 soldiers whose power is <=3 and the sum of their power is 1+2+3=6\n\ntherefore ans= 3 6\n\nsame for the next round.

“TESTCASE_1”: “7\n1 2 3 4 5 6 7\n3\n3\n10\n2\n###—###SEPERATOR—###—\n3 6\n7 28\n2 3”, “TESTCASE_2”: “5\n4 3 6 7 9\n3\n4\n3\n5\n###—###SEPERATOR—###—\n2 7\n1 3\n2 7”, “TESTCASE_3”: “9\n2 3 5 4 5 9 7 4 6\n6\n4 \n7\n6\n1\n9\n4\n###—###SEPERATOR—###—\n4 13\n8 36\n7 29\n0 0\n9 45\n4 13”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <iostream>
using namespace std;
int main()
{ int n,q,a[100];
   cin>>n;
   for(int i=0;i<n;i++)
     cin>>a[i];
   cin>>q;
   while(q--)
   { 
     int pow;
     cin>>pow;
     int count=0,sum=0;
     for(int i=0;i<n;i++)
     {
       if(a[i]<=pow)
       {
         count++;
         sum+=a[i];
       }
     }
     cout<<count<<" "<<sum<<"\n";
   }

	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.