91442024-02-15 21:31:58UVinceMI bróker (50 pont)cpp17Time limit exceeded 4/501.1s4480 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    int dp[501][501];
    for (int i = 1; i <= 500; i++)
    {
        for (int j = i + 1; j <= 500; j++)
        {
            int win = 0;
            bool own = false;
            for (int z = 0; z < n; z++)
            {
                if (!own && v[z] <= i)
                {
                    win -= v[z];
                    own = true;
                }
                else if (own && v[z] >= j)
                {
                    win += v[z];
                    own = false;
                }
            }
            dp[i][j] = win;
        }
    }

    for (int i = 0; i < q; i++)
    {
        int v, e;
        cin >> v >> e;
        cout << dp[v][e] << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/04ms3820 KiB
2Time limit exceeded0/01.1s2576 KiB
3Accepted1/14ms4388 KiB
4Accepted1/14ms4480 KiB
5Accepted2/2170ms4440 KiB
6Time limit exceeded0/21.054s2792 KiB
7Time limit exceeded0/21.06s3308 KiB
8Time limit exceeded0/11.05s3264 KiB
9Time limit exceeded0/11.065s3228 KiB
10Time limit exceeded0/21.07s3284 KiB
11Time limit exceeded0/21.065s3328 KiB
12Time limit exceeded0/21.065s3428 KiB
13Time limit exceeded0/21.065s3344 KiB
14Time limit exceeded0/21.07s3392 KiB
15Time limit exceeded0/31.057s3644 KiB
16Time limit exceeded0/31.07s3448 KiB
17Time limit exceeded0/31.077s3532 KiB
18Time limit exceeded0/31.054s3388 KiB
19Time limit exceeded0/31.065s3340 KiB
20Time limit exceeded0/31.077s3684 KiB
21Time limit exceeded0/31.082s3708 KiB
22Time limit exceeded0/31.065s3716 KiB
23Time limit exceeded0/31.082s4000 KiB
24Time limit exceeded0/31.077s4036 KiB