94902024-02-22 11:41:35zeytonxMI bróker (50 pont)cpp17Time limit exceeded 8/501.1s5312 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl "\n"
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define fs first
#define sc second

const ll MOD = 1e9+7;

void solve()
{
	ll n, q;
	cin >> n >> q;
	vector<ll> p(n);
	for(ll &i : p)
		cin >> i;
	vector<pll> qr(q);
	for(auto &i : qr)
		cin >> i.fs >> i.sc;
	
	for(auto i : qr)
	{
		ll ans = 0;
		bool own = false;
		for(ll j = 0; j < n; j++)
		{
			if(!own && p[j] <= i.fs)
			{
				own = true;
				ans -= p[j];
			}
			else
			if(own && p[j] >= i.sc)
			{
				own = false;
				ans += p[j];
			}
		}
		cout << ans << "\n";
	}
	cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base8/50
1Accepted0/03ms1828 KiB
2Time limit exceeded0/01.1s2932 KiB
3Accepted1/13ms2240 KiB
4Accepted1/13ms2332 KiB
5Accepted2/23ms2456 KiB
6Accepted2/24ms2608 KiB
7Accepted2/24ms2604 KiB
8Time limit exceeded0/11.067s4428 KiB
9Time limit exceeded0/11.062s4712 KiB
10Time limit exceeded0/21.042s4888 KiB
11Time limit exceeded0/21.075s5148 KiB
12Time limit exceeded0/21.054s5012 KiB
13Time limit exceeded0/21.067s5068 KiB
14Time limit exceeded0/21.075s5196 KiB
15Time limit exceeded0/31.019s5312 KiB
16Time limit exceeded0/31.07s5260 KiB
17Time limit exceeded0/31.08s5220 KiB
18Time limit exceeded0/31.07s5184 KiB
19Time limit exceeded0/31.059s5232 KiB
20Time limit exceeded0/31.067s5292 KiB
21Time limit exceeded0/31.067s5240 KiB
22Time limit exceeded0/31.054s5300 KiB
23Time limit exceeded0/31.07s5304 KiB
24Time limit exceeded0/31.055s5132 KiB