32272023-02-22 21:04:05zsomborVállalkozócpp17Accepted 40/4032ms5300 KiB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n, m, kesz = 0, ans = 0;
vector <int> o(1e4 + 1);
vector <int> v;

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> o[i];
    v.resize(m);
    for (int& i : v) cin >> i;
    sort(v.begin(), v.end());
    for (int i = 1; i <= n; i++) {
        int h = lower_bound(v.begin(), v.end(), i) - v.begin();
        kesz = max(kesz, h);
        if (kesz + o[i] > m) { ans += m - kesz; break; }
        kesz += o[i];
        ans += o[i];
    }
    cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1916 KiB
2Accepted0/032ms2892 KiB
3Accepted2/23ms2552 KiB
4Accepted2/23ms2764 KiB
5Accepted2/23ms2980 KiB
6Accepted2/24ms3200 KiB
7Accepted2/24ms3420 KiB
8Accepted2/23ms3364 KiB
9Accepted2/24ms3440 KiB
10Accepted2/23ms3744 KiB
11Accepted2/24ms3868 KiB
12Accepted2/24ms4076 KiB
13Accepted2/24ms4100 KiB
14Accepted2/24ms4360 KiB
15Accepted2/210ms4372 KiB
16Accepted2/210ms4472 KiB
17Accepted2/214ms4448 KiB
18Accepted2/210ms4556 KiB
19Accepted2/213ms4624 KiB
20Accepted2/217ms4864 KiB
21Accepted2/224ms5108 KiB
22Accepted2/232ms5300 KiB