include iostream include vector using namespace std int main int cin v

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n, m, k;
cin >> n >> m >> k;
vector<int> num(n);
vector< vector<int> > sum(n, vector<int>(n));
for (int i = 0; i < n; ++i)
{
cin >> num[i];
sum[0][i] = num[i];
sum[i][0] = num[0];
}
for(int i = 1; i < n; ++i)
for (int j = 1; j < n; ++j)
{
sum[i][j] = sum[i - 1][j - 1] + sum[0][j];
}
int t = n + m;
int next = 0, bef = 0, step, now = 0;
for (int i = 1; i <= m; ++i)
{
cin >> next;
step = next - bef - 1;
now += step;
int l = 0;
while (sum[l][now - 1] < k && l < n - 1)
l++;
if (now >= l + 1)
now -= l + 1;
else
{
l = now - 1;
now = 0;
}
t += l + 1;
bef = next;
}
cout << t << endl;
return 0;
}