94932024-02-22 11:55:26zeytonxMI bróker (50 pont)cpp17Time limit exceeded 9/501.078s7632 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;
		ll index = 0;
		while(index < n)
		{
			while(index < n && p[index] > i.fs)
				index++;
			if(index != n && p[index] <= i.fs)
			{
				ans -= p[index];
				index++;
				while(index < n && p[index] < i.sc)
					index++;
				if(index != n && p[index] >= i.sc)
				{
					ans += p[index];
					index++;
				}
			}
		}
		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
base9/50
1Accepted0/03ms2104 KiB
2Time limit exceeded0/01.07s3028 KiB
3Accepted1/13ms2156 KiB
4Accepted1/13ms2236 KiB
5Accepted2/23ms2464 KiB
6Accepted2/26ms2872 KiB
7Accepted2/24ms3136 KiB
8Accepted1/1818ms7632 KiB
9Time limit exceeded0/11.046s4724 KiB
10Time limit exceeded0/21.059s4620 KiB
11Time limit exceeded0/21.055s4872 KiB
12Time limit exceeded0/21.075s5064 KiB
13Time limit exceeded0/21.059s5188 KiB
14Time limit exceeded0/21.065s5136 KiB
15Time limit exceeded0/31.062s5560 KiB
16Time limit exceeded0/31.059s5360 KiB
17Time limit exceeded0/31.039s5680 KiB
18Time limit exceeded0/31.062s5908 KiB
19Time limit exceeded0/31.07s5952 KiB
20Time limit exceeded0/31.07s5800 KiB
21Time limit exceeded0/31.072s6036 KiB
22Time limit exceeded0/31.067s6032 KiB
23Time limit exceeded0/31.05s6012 KiB
24Time limit exceeded0/31.078s6176 KiB