Please read the new rule regarding the restriction on the use of AI tools. ×

Can Anyone help me how i can fix TLE in this code. problem name(PROMO).

Revision en1, by dipesh_ait, 2022-11-16 12:05:34

include <bits/stdc++.h>

using namespace std;

define ll long long

int32_t main() { ll n,q; cin>>n>>q; ll a[n]; for(ll i=0;i<n;i++) { cin>>a[i]; }
sort(a,a+n);
vector<pair<ll,ll>> v_p; for(ll i=0;i<q;i++) { ll x,y; cin>>x>>y; v_p.push_back({x,y}); } for(auto h:v_p) { ll x_temp = h.first; ll y_temp = h.second; ll x_n = n; ll y_n = x_temp; vector v; ll total = 0; while(x_temp--) { v.push_back(a[x_n-1]); x_n--; } while(y_temp--) { total+=v[y_n-1]; y_n--; } cout<<total<<endl; } return 0; }

Tags bug, tle, howtofix, help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English dipesh_ait 2022-11-16 12:07:02 20
en1 English dipesh_ait 2022-11-16 12:05:34 853 Initial revision (published)