-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18311왕복.cpp
62 lines (51 loc) · 791 Bytes
/
18311왕복.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
56
57
58
59
60
61
62
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
vector<int>v;
int N;
int num;
long long sum = 0;
long long K;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> num;
v.push_back(num);
sum += num;
}
if (K >= sum) {
K -= sum;
for (int i = N-1; i >= 0; i--) {
K -= v[i];
if (K < 0) {
cout << i + 1;
break;
}
else if (K == 0) {
cout << i;
break;
}
}
}
else {
for (int i = 0; i < N; i++) {
K -= v[i];
if (K < 0) {
cout << i + 1;
break;
}
else if (K == 0) {
cout << i + 2;
break;
}
}
}
return 0;
}