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
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, d, a, b;
cin >>n >>d >>a >>b;
vector <int> pr(n);
for (int i = 0; i < n; ++i) {
cin >>pr[i];
}
int ans = 0, old_a = a, old_b = b;
for (int i = 1; i < n; ++i) {
if (pr[i] > pr[i - 1]) {
for (int j = 0; j < a && d >= pr[i]; ++j) {
ans++;
d -= pr[i];
}
a += old_a;
} else if (pr[i] < pr[i - 1]) {
for (int j = 0; j < b && ans > 0; ++j) {
ans--;
d += pr[i];
}
b += old_b;
}
}
cout <<d <<' ' <<ans <<endl;
return 0;
}