89812024-02-09 17:04:39bovizdbMI bróker (50 pont)cpp17Time limit exceeded 2/501.1s12172 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define fs first
#define sc second

struct s
{
	ll a, b, i;
};

ll n, m;
vll v, buy, sell, ans;
vector<pll> q, q2;
vector<bool> b;

int main() {
	cin >> n >> m;
	v.resize(n);
	q.resize(m);
	q2.resize(m);
	b.resize(m);
	ans.resize(m);
	buy.resize(m);
	sell.resize(m);
	for (ll i = 0; i <n; i++) cin >> v[i];
	for (ll i = 0; i < m; i++)
	{
		cin >> q[i].fs >> q2[i].fs;
		q[i].sc = i;
		q2[i].sc = i;
	}
	sort(q.rbegin(), q.rend());
	sort(q2.begin(), q2.end());
	/* for (ll i = 0; i < m; i++)
	{
		cout << q[i].fs << " " << q2[i].fs << endl;
	} */
	for (ll i = 0; i < n; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			if (v[i] > q[j].fs)
			{
				break;
			}
			if (v[i] <= q[j].fs && b[q[j].sc] == 0)
			{
				b[q[j].sc] = 1;
				ans[q[j].sc] -= v[i];
				buy[j] += v[i];
			}
		}
		for (ll j = 0; j < m; j++)
		{
			if (v[i] < q2[j].fs)
			{
				break;
			}
			if (v[i] >= q[j].fs && b[q2[j].sc] == 1)
			{
				b[q2[j].sc] = 0;
				ans[q2[j].sc] += v[i];
				sell[j] += v[i];
			}
		}
	}
	/* for (ll i = 0; i < m; i ++)
	{
		cout << sell[i] << endl;
	}
	for (ll i = 0; i < m; i++)
	{
		ans[q[i].sc] -= buy[i];
		ans[q2[i].sc] += sell[i];
	} */
	for (ll i : ans) cout << i << endl;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/03ms2148 KiB
2Time limit exceeded0/01.062s6400 KiB
3Accepted1/13ms2308 KiB
4Accepted1/13ms2552 KiB
5Wrong answer0/23ms2616 KiB
6Wrong answer0/27ms2684 KiB
7Wrong answer0/27ms2948 KiB
8Time limit exceeded0/11.055s10572 KiB
9Time limit exceeded0/11.1s10704 KiB
10Time limit exceeded0/21.062s10760 KiB
11Time limit exceeded0/21.067s10896 KiB
12Time limit exceeded0/21.075s11028 KiB
13Time limit exceeded0/21.082s10936 KiB
14Time limit exceeded0/21.062s10952 KiB
15Time limit exceeded0/31.034s11148 KiB
16Time limit exceeded0/31.072s11360 KiB
17Time limit exceeded0/31.067s11476 KiB
18Time limit exceeded0/31.052s11736 KiB
19Time limit exceeded0/31.054s11672 KiB
20Time limit exceeded0/31.072s11936 KiB
21Time limit exceeded0/31.059s11880 KiB
22Time limit exceeded0/31.072s12116 KiB
23Time limit exceeded0/31.067s12120 KiB
24Time limit exceeded0/31.07s12172 KiB