Codeforces Round #827 (Div. 4) 1742E. Scuza Solution
Problem Link: https://codeforces.com/problemset/problem/1742/E
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************/
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- ll n,q,i,t,mx=0,x;
- vector<int>v;
- cin>>n>>q;
- ll a[n+1];
- for(i=1; i<=n; i++)
- {
- cin>>a[i];
- mx=max(mx,a[i]);
- v.push_back(mx);
- }
- a[0]=0;
- for(i=2; i<=n; i++)
- {
- a[i]+=a[i-1];
- }
- while(q--)
- {
- cin>>x;
- int index;
- index=upper_bound(v.begin(),v.end(),x)-v.begin();
- cout<<a[index]<<" ";
- }
- cout<<endl;
- }
- }
No comments