78102024-01-11 10:50:311478MI bróker (50 pont)cpp17Time limit exceeded 8/501.1s4976 KiB
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
int main()
{
    //ifstream cin("in.txt");
    int n;
    cin >> n;
    int q;
    cin >> q;
    vector<int> price(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> price[i];
    }
    while(q--){
        int b, s;
        cin >> b >> s;
        bool has = false;
        int ans = 0;
        for(int i = 1; i <= n; i++){
            if(price[i] <= b && !has){
                ans -= price[i];
                has = true;
            }
            if(price[i] >= s && has){
                ans += price[i];
                has = false;
            }
        }
        cout << ans << '\n';
    }
}
SubtaskSumTestVerdictTimeMemory
base8/50
1Accepted0/03ms1808 KiB
2Time limit exceeded0/01.1s1416 KiB
3Accepted1/13ms2336 KiB
4Accepted1/13ms2428 KiB
5Accepted2/24ms2644 KiB
6Accepted2/28ms3044 KiB
7Accepted2/28ms3264 KiB
8Time limit exceeded0/11.1s2460 KiB
9Time limit exceeded0/11.054s2624 KiB
10Time limit exceeded0/21.057s3036 KiB
11Time limit exceeded0/21.067s3136 KiB
12Time limit exceeded0/21.062s2924 KiB
13Time limit exceeded0/21.054s3968 KiB
14Time limit exceeded0/21.067s3436 KiB
15Time limit exceeded0/31.046s3676 KiB
16Time limit exceeded0/31.049s4024 KiB
17Time limit exceeded0/31.062s3772 KiB
18Time limit exceeded0/31.039s3812 KiB
19Time limit exceeded0/31.07s4124 KiB
20Time limit exceeded0/31.034s4976 KiB
21Time limit exceeded0/31.047s4820 KiB
22Time limit exceeded0/31.075s4096 KiB
23Time limit exceeded0/31.039s4244 KiB
24Time limit exceeded0/31.064s4184 KiB