-
Notifications
You must be signed in to change notification settings - Fork 0
/
aln.cpp
55 lines (51 loc) · 842 Bytes
/
aln.cpp
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
48
49
50
51
52
53
54
55
#include<iostream>
using namespace std;
int main()
{
int n,max;
cin >> n >> max;
int a[n],b[n],at[n],bt[n];
for(int i = 0;i < n;i++) {
cin >> a[i];
}
for(int j = 0;j < n;j++) {
cin >> b[j];
}
at[0] = a[0];
bt[0] = b[0];
for(int i = 1;i < n;i++) {
if(at[i-1]+a[i] < bt[i-1]+b[i]+a[i]) {
at[i] = at[i-1]+a[i];
}else {
at[i] = bt[i-1]+b[i]+a[i];
}
if(bt[i-1]+b[i] < at[i-1]+a[i]+b[i]) {
bt[i] = bt[i-1]+b[i];
}else {
bt[i] = at[i-1]+a[i]+b[i];
}
}
int q,temp;
for(int k = n-1;k >= 0;k--) {
if(at[k] < bt[k]) {
if(at[k] <= max) {
q = 1;
temp = k;
}
}else {
if(bt[k] <= max) {
q = 2;
temp = k;
}
}
if(q == 1||q == 2) {
break;
}
}
if(q == 1) {
cout << temp+1 << " " << at[temp] << endl;
}else {
cout << temp+1 << " " << bt[temp] << endl;
}
return 0;
}