Sunday, February 9, 2020

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;
}

No comments:

Post a Comment