94952024-02-22 11:57:51AblablablaMI bróker (50 pont)cpp17Accepted 50/50423ms6092 KiB
#include<bits/stdc++.h>

using namespace std;

const int MAXA = 501;

int main(){
    int n, q;
    cin >> n >> q;

    vector<int> szamok(n);
    for(int &x : szamok){
        cin >> x;
    }

    vector<vector<int>> valasz(MAXA + 5, vector<int>(MAXA + 5, 0));

    for(int v = 1; v <= MAXA; v++){
        int e = MAXA;
        for(int x : szamok){
            if(x <= v){
                valasz[v][v + 1] -= x;
                valasz[v][e] += x;
                e = v + 1;
            } else if(x >= e){
                valasz[v][e] += x;
                valasz[v][x + 1] -= x;
                e = x + 1;
            }
        }

        for(int i = v + 1; i <= MAXA; i++){
            valasz[v][i] += valasz[v][i - 1];
        }
    }

    while(q--){
        int e, v;
        cin >> v >> e;

        cout << valasz[v][e] << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/04ms3852 KiB
2Accepted0/0174ms4132 KiB
3Accepted1/14ms4256 KiB
4Accepted1/14ms4464 KiB
5Accepted2/26ms4560 KiB
6Accepted2/237ms4604 KiB
7Accepted2/237ms4604 KiB
8Accepted1/1261ms4880 KiB
9Accepted1/1261ms5100 KiB
10Accepted2/2270ms5140 KiB
11Accepted2/2266ms5136 KiB
12Accepted2/2268ms5132 KiB
13Accepted2/2270ms5360 KiB
14Accepted2/2273ms5332 KiB
15Accepted3/3270ms5484 KiB
16Accepted3/3402ms5560 KiB
17Accepted3/3268ms5552 KiB
18Accepted3/3273ms5548 KiB
19Accepted3/3282ms5548 KiB
20Accepted3/3414ms5552 KiB
21Accepted3/3266ms5560 KiB
22Accepted3/3423ms5816 KiB
23Accepted3/3268ms5920 KiB
24Accepted3/3275ms6092 KiB