Question Name:Bishu and Soldiers

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,i;
    cin>>n;
    vector<int>v(n);
    for(i=0;i<n;i++)
    cin>>v[i];
    sort(v.begin(),v.end());
    int q;
    cin>>q;
    while(q--)
    {
        int p,sum=0,j=0;
      cin>>p;
      for(i=0;i<n;i++)
      {
          if(v[i]>p)
          break;
          sum+=v[i];
          j++;
        }  
        cout<<j<<" "<<sum<<"\n";
    }
    return 0;
}
  • Problem Description
    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.

    1<=N<=10000

    1<=power of each soldier<=100

    1<=Q<=10000

    1<=power of bishu<=100
  • Test Case 1
    Input (stdin)4
    1 2 3 4
    3
    3
    10
    2
    Expected Output3 6
    4 10
    2 3
  • Test Case 2
    Input (stdin)7
    1 2 3 4 5 6 7
    3
    3
    10
    2
    Expected Output3 6
    7 28
    2 3
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.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock