201632026-01-03 14:41:51szabelrSzínes szobák (50 pont)cpp17Wrong answer 0/5045ms5396 KiB
// Színes szobák.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;
int binkeres(vector<int> &a,int x) {
    int bal = 1;
    int jobb = a.size() - 1;
    int mid = (bal + jobb) / 2;
    while (bal <= jobb)
    {
        mid = (bal + jobb) / 2;
        if (a[mid] < x)
        {
            bal = mid + 1;

        }
        else
            jobb = mid - 1;
    }
    return mid;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, c,m;
    cin >> n >> c>>m;
    int emberek = 0;
    vector<vector<int>> color(c+1);
    vector<int> sum(c + 1,0);
    vector<int> maxi(c + 1,0);
    vector<int> mini(c + 1,0);
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        color[x].push_back(i);
    }
    for (int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;
        sum[x] += y;
        maxi[x] = max(maxi[x], sum[x]);
        mini[x] = min(mini[x], sum[x]);
    }
    for (int i = 1; i <= c; i++)
    {
        if(!color[i].empty())
        {
            int balhatar=1, jobbhatar=color[i].size()-1;
            if (mini[i] < 0)
                balhatar= binkeres(color[i], abs(mini[i]));
            if (maxi[i] > 0)
                jobbhatar= binkeres(color[i], color[i].size() - maxi[i]);
            emberek = emberek + (color[i].size()-1 - (jobbhatar - balhatar));
        }
       
    }
    cout << emberek;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/01ms316 KiB
2Wrong answer0/039ms4688 KiB
3Wrong answer0/11ms316 KiB
4Wrong answer0/11ms316 KiB
5Wrong answer0/11ms316 KiB
6Wrong answer0/11ms316 KiB
7Wrong answer0/11ms508 KiB
8Wrong answer0/11ms508 KiB
9Wrong answer0/11ms316 KiB
10Wrong answer0/12ms316 KiB
11Wrong answer0/11ms316 KiB
12Wrong answer0/12ms316 KiB
13Wrong answer0/14ms564 KiB
14Wrong answer0/13ms820 KiB
15Wrong answer0/14ms824 KiB
16Wrong answer0/14ms820 KiB
17Wrong answer0/14ms824 KiB
18Wrong answer0/14ms836 KiB
19Wrong answer0/125ms1572 KiB
20Wrong answer0/135ms1588 KiB
21Wrong answer0/128ms1532 KiB
22Wrong answer0/130ms1520 KiB
23Wrong answer0/132ms1608 KiB
24Wrong answer0/135ms1472 KiB
25Wrong answer0/135ms1564 KiB
26Wrong answer0/135ms1572 KiB
27Wrong answer0/341ms5288 KiB
28Wrong answer0/341ms5396 KiB
29Wrong answer0/345ms5276 KiB
30Wrong answer0/345ms5296 KiB
31Wrong answer0/345ms5292 KiB
32Wrong answer0/341ms5160 KiB
33Wrong answer0/420ms2712 KiB
34Wrong answer0/429ms2900 KiB