Bishu Coding Club

QUESTION

Bishu went to fight for Coding Club. There were N soldiers with various powers. \n\nThere will be Q rounds to fight and in each round Bishu’s power will be varied. \n\nWith power M, Bishu can kill all the soldiers whose power is less than or equal to M(<=M). \n\nAfter 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. \n\nAs 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.

“TESTCASE_1”: “7\n1 2 3 4 5 6 7\n3\n3 10 2\n###—###SEPERATOR—###—\n3 6\n7 28\n2 3”, “TESTCASE_2”: “7\n2 3 4 5 6 7 1 \n4\n4 5 6 8\n###—###SEPERATOR—###—\n4 10\n5 15\n6 21\n7 28”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int s[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    int q;
    scanf("%d",&q);
    while(q--){
        int p;
        int count=0,sum=0;
        scanf("%d",&p);
        for(i=0;i<n;i++){
            if(s[i]<=p){
                count++;
                sum+=s[i];
            }
        }
 
        printf("%d %d\n",count,sum);
    }
    
    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.