-
Notifications
You must be signed in to change notification settings - Fork 0
/
Minimum_Emission.cpp
54 lines (51 loc) · 966 Bytes
/
Minimum_Emission.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll find_fuel(vector<int>& A, int l, int r, int x, int y) {
vector<int> arr(A.begin()+l,A.begin()+r);
sort(arr.begin(),arr.end());
ll sum=0;
int i, n=r-l;
for(i=0;i<x;i++)
sum+=arr[i];
for(;i<n&&arr[i]<0&&i<y;i++)
sum+=arr[i];
return sum;
}
vector<ll> min_emission_SAF(int n, vector<int>& A, int q, vector<vector<int>>& Q) {
vector<ll> res;
int l, r, x, y;
ll ret;
for(vector<int> query: Q) {
l=query[0];
r=query[1];
x=query[2];
y=query[3];
ret=find_fuel(A,l,r,x,y);
res.push_back(ret);
}
return res;
}
int main() {
int t, n, q, i;
int l, r, x, y;
cin>>t;
while(t--) {
cin>>n;
vector<int> A(n);
for(i=0;i<n;i++)
cin>>A[i];
cin>>q;
vector<vector<int>> Q;
for(i=0;i<q;i++) {
cin>>l>>r>>x>>y;
l--;
Q.push_back({l,r,x,y});
}
vector<ll> res=min_emission_SAF(n,A,q,Q);
for(i=0;i<q;i++)
cout<<res[i]<<" ";
cout<<endl;
}
return 0;
}