#### [b964. 1. 成績指標](https://zerojudge.tw/ShowProblem?problemid=b964)
- python - 1
```python=
n = []
s = []
a = int(input())
b = list(map(int, input().split()))
b.sort()
for i in range(a):
if b[i]<60:
n.append(b[i])
else:
s.append(b[i])
print(' '.join(map(str,b)))
if n != [] :
print(max(n))
else:
print("best case")
if s != [] :
print(min(s))
else :
print("worst case")
```
- python - 2
```py=
a = int(input()) # 學生人數
b = [int(i) for i in input().split()]
b.sort()
print(" ".join(map(str,b)))
if b[0] >= 60 :
print("best case")
else :
print(max([int(i) for i in b if i<60]))
if b[-1] < 60 :
print("worst case")
else :
print(min([int(i) for i in b if i>=60]))
```
:::success
```\n``` 換行符號
:::
- cpp
```cpp=
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
int z = 0 , g = 0;
int maxs = 0,mins = 100;
cin >> n;
int a[n];
for (int i = 0; i < n; i++){
cin >> a[i];
//cout << a[i] << " ";
if (a[i] >= 60)
mins = min(mins,a[i]) , z += 1;
else
maxs = max(maxs,a[i]) , g += 1;
}
sort(a, a+n);
for (int i = 0; i < n; i++)
cout << a[i] << " ";
cout << endl;
if (z == 0 and g != 0){
cout << maxs << "\nworst case";
else if (z!=0 and g==0){
cout << "best case\n" << mins;
else
cout << maxs << '\n' << mins;
return 0;
}
```
#### [c290. APCS 2017-0304-1秘密差](https://zerojudge.tw/ShowProblem?problemid=c290)
:::success
```[::-1]``` 從最後一個到第一的
:::
- python - 1
```python=
s = input()
ans = 0
b = 0
for i in range(len(s))[::-1]:
ans += (ord(s[i]) - ord('0'))* pow(-1 , b)
b+= 1
print(abs(ans))
```
- python - 2
```python=
n = [int(i) for i in input()]
print(abs(sum([n[i] for i in range(len(n)) if i % 2 == 0]) - sum([n[i] for i in range(len(n)) if i % 2 == 1])))
```
- cpp
```cpp=
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
string s;
cin >> s;
int ans = 0 , len = s.size() , b = 0;
for (auto str : s)
ans += int(str - '0') * pow(-1 , b) , b++;
cout << abs(ans);
}
```
#### [c294. APCS-2016-1029-1三角形辨別](https://zerojudge.tw/ShowProblem?problemid=c294)
- python
```python=
a = list(map(int,input().split()))
a.sort()
print(' '.join(map(str,a)))
if a[0] + a[1] <= a[2]:
print('No')
elif a[0]*a[0] +a[1]*a[1] <a[2]*a[2] :
print('Obtuse')
elif a[0]*a[0] + a[1]*a[1] == a[2]*a[2] :
print('Right')
else:
print('Acute')
```
- cpp
```cpp=
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int a[3];
for (int i = 0; i < 3; i++) cin >> a[i];
sort(a ,a+3);
for (int i = 0; i < 3; i++) cout << a[i] << " ";
cout << endl;
if (a[0] + a[1] <= a[2]) cout << "No";
else if (a[0]*a[0] +a[1]*a[1] <a[2]*a[2])
cout << "Obtuse";
else if (a[0] *a[0] + a[1] *a[1] == a[2] *a[2])
cout << "Right";
else cout << "Acute";
}
```
#### [c461. apcs 邏輯運算子 (Logic Operators)](https://zerojudge.tw/ShowProblem?problemid=c461)
-python
```python=
a , b , c = map(int,input().split())
c = bool(c)
a = 1 if a != 0 else 0
b = 1 if b != 0 else 0
if a & b == c:
print('AND')
if a | b == c:
print('OR')
if a ^b == c:
print('XOR')
if (a & b != c) and (a | b != c) and (a ^ b !=c ):
print('IMPOSSIBLE')
```
- cpp
```cpp=
#include<iostream>
using namespace std;
int main(){
int a , b;
bool c;
cin >> a >> b >> c;
a=(a!=0?1:0) , b=(b!=0?1:0);
bool cmp=0;
if((a&&b) == c){
cmp = 1;
cout << "AND\n";
}
if((a||b) == c){
cmp = 1;
cout << "OR\n";
}
if((a^b) == c){
cmp = 1;
cout << "XOR\n";
}
if(cmp == 0) cout << "IMPOSSIBLE";
}
```
#### [e283. APCS 類似題 - 小崴的特殊編碼](https://zerojudge.tw/ShowProblem?problemid=e283)
※ python 一定要用 sys 模組讀喔 不然會TLE
- python
```python=
import sys
letter = {"0 1 0 1": "A",
"0 1 1 1": "B",
"0 0 1 0": "C",
"1 1 0 1": "D",
"1 0 0 0": "E",
"1 1 0 0": "F"}
for i in sys.stdin:
n = int(i)
ans = ""
for i in range(n):
s = sys.stdin.readline().strip()
ans += letter[s]
print (ans)
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
while (cin >> n && !cin.eof()){
for (int i = 0; i < n; i++){
int a , b , c , d;
cin >> a >> b >> c >> d;
if (a == 0){
if (b == 1){
if (c == 0) cout << "A";
else cout << "B";
}
else cout << "C";
}
else{
if (b == 1){
if (d == 1) cout << "D";
else cout << "F";
}
else cout << "E";
}
}
cout << endl;
}
}
}
```
#### [e286. 籃球比賽](https://zerojudge.tw/ShowProblem?problemid=e286)
- python - 1
```python=
h1 = sum(list(map(int , input().split())))
g1 = sum(list(map(int , input().split())))
h2 = sum(list(map(int , input().split())))
g2 = sum(list(map(int , input().split())))
if h1 > g1 and h2 > g2:
print(f'{h1}:{g1}\n{h2}:{g2}\nWin')
elif h1 < g1 and h2 < g2:
print(f'{h1}:{g1}\n{h2}:{g2}\nLose')
else:
print(f'{h1}:{g1}\n{h2}:{g2}\nTie')
```
- python - 2
```python=
a1,b1,a2,b2=[sum(map(int,input().split())) for i in range(4)]
print(f'{a1}:{b1}\n{a2}:{b2}')
if a1>b1 and a2>b2:
print('Win')
elif a1<b1 and a2<b2:
print("Lose")
else:
print("Tie")
```
- python - 3
```python=
# 讀入測資字串,切割後,轉整數,再轉為list
home1 = sum( list( map(int, input().split() ) ) ) # 主隊第1場得分
guest1 = sum( list( map(int, input().split() ) ) ) # 客隊第1場得分
home2 = sum( list( map(int, input().split() ) ) ) # 主隊第2場得分
guest2 = sum( list( map(int, input().split() ) ) ) # 客隊第2場得分
home_win = 0 # 主隊贏幾場
ans = ["Lose" , "Tie" , "Win"]
print( f"{home1}:{guest1}" ) # 輸出第1場兩隊比分
print( f"{home2}:{guest2}" ) # 輸出第2場兩隊比分
if home1 > guest1 : # 如果主隊贏第一場
home_win+=1 # 主隊贏場數+1
if home2 >guest2 : # 如果主隊贏第二場
home_win+=1 # 主隊贏場數+1
print(ans[home_win])
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int MAP[4][4] , sum[4];
int n = 4 , sumi = 0;
for (int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> MAP[i][j];
sumi += MAP[i][j];
}
sum[i] = sumi;
sumi = 0;
}
cout << sum[0] << ":" << sum[1] << endl;
cout << sum[2] << ":" << sum[3] << endl;
if (sum[0] > sum[1] && sum[2]>sum[3]) cout << "Win";
else if (sum[0] < sum[1] && sum[2] < sum[3]) cout <<"Lose";
else cout << "Tie";
return 0;
}
```
#### [e313. 最少相異字母](https://zerojudge.tw/ShowProblem?problemid=e313)
- python
```python=
def find(strings):
mins = float('inf')
c = []
for s in strings:
dis = len(set(s)) # 計算不同字母的數量
if dis < mins:
mins = dis
c = [s]
elif dis == mins:
c.append(s)
return min(c)
n = int(input())
strings = [input().strip() for _ in range(n)]
result = find(strings)
print(result)
```
- cpp
```cpp=
#include <iostream>
#include <set>
#include <climits>
using namespace std;
int main() {
int n;
cin >> n;
set<char> cSet;
set<string> str;
string s;
int mins = INT_MAX;
for (int i = 0; i < n; i++) {
cin >> s;
cSet.clear();
for (char c : s) {
cSet.insert(c);
}
if (cSet.size() < mi ns)
mins = cSet.size() , str.clear() , str.insert(s);
else if (cSet.size() == mins)
str.insert(s);
}
cout << *str.begin() << endl;
return 0;
}
```
#### [f312. 1. 人力分配](https://erojudge.tw/ShowProblem?problemid=f312)
- python
```py=
ans=[]
a1,b1,c1=map(int , input().split())
a2,b2,c2=map(int , input().split())
n=int(input())
for i in range(n+1):
j = n-i
ans.append(a1*i*i + b1*i + c1 + a2*j*j + b2*j+c2)
print(max(ans))
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int n;
int a1 , b1 , c1 , a2 , b2 , c2;
int y1 , y2 , a;
cin >> a1 >> b1 >> c1;
cin >> a2 >> b2 >> c2;
cin >> n;
for (int i = 0; i <= n; i++){
int j = n-i;
y1 = a1*i*i + b1*i + c1;
y2 = a2*j*j + b2*j + c2;
if (i == 0) a = y1+y2;
else
if (y1+y2 > a)
a = y1+y2;
}
cout << a;
return 0;
}
```
#### [f579. 1. 購物車](https://zerojudge.tw/ShowProblem?problemid=f579)
- python
```python=
a , b = map(int , input().split())
n = int(input())
d = 0
for _ in range(n):
cart = list(map(int, input().split()))
a_cart = cart.count(a) - cart.count(-a)
b_cart = cart.count(b) - cart.count(-b)
if a_cart > 0 and b_cart > 0:
d += 1
print(d)
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int a , b , n;
cin >> a >> b >> n;
int m;
int anum = 0 , bnum = 0 , ans = 0;
for (int i = 0; i < n; i++){
while (m != 0){
cin >> m;
if (m == a) anum++;
else if (m == b) bnum++;
else if (m == (-1*a)) anum--;
else if (m == (-1*b)) bnum--;
}
if (anum > 0 && bnum > 0)
ans += 1;
anum = 0 , bnum = 0 , m = 1;
}
cout << ans;
return 0;
}
```
#### [f605. 1. 購買力](https://zerojudge.tw/ShowProblem?problemid=f605)
- python
```python=
n , d = map(int , input().split())
s = []
flag = 0
for i in range(n):
c = list(map(int , input().split()))
if (max(c) - min(c)) >= d:
a = sum(c) / len(c)
s.append(a)
flag +=1
print(flag , int(sum(s)))
```
- cpp
```cpp=
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n , d;
cin >> n >> d;
int s[3] , sums = 0 , flag = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < 3; j++) cin >> s[j];
sort(s , s+3);
if (s[2] - s[0] >= d)
sums += (s[0] + s[1] + s[2]) / 3 , flag++;
}
cout << flag << " " << sums;
}
```
#### [g275. 1. 七言對聯](https://zerojudge.tw/ShowProblem?problemid=g275)
- python
```python=
n = int(input())
out = []
for _ in range(n):
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if (a[1] == a[3]) | (a[1] != a[5]) | (b[1] == b[3]) | (b[1] != b[5]):
out.append("A")
if (a[6] != 1) | (b[6] != 0):
out.append("B")
if (a[1] == b[1]) | (a[3] == b[3]) | (a[5] == b[5]):
out.append("C")
print("".join(out)) if out != [] else print("None")
out = []
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
int a[n] , b[n];
for (int _ = 0; _ < n; _++){
for (int i = 0; i < 7; i++) cin >> a[i];
for (int i = 0; i < 7; i++) cin >> b[i];
bool c = 0;
if (a[1] == a[3] || a[1] != a[5] || b[1] == b[3] || b[1] != b[5]){
c = 1;
cout << "A";
}
if (a[6] != 1 || b[6] != 0){
c = 1;
cout << "B";
}
if (a[1] == b[1] || a[3] == b[3] || a[5] == b[5]){
c = 1;
cout << "C";
}
if (c == 0)
cout << "None";
cout << endl;
}
return 0;
}
```
#### [g595. 1. 修補圍籬](https://zerojudge.tw/ShowProblem?problemid=g595)
- python
```python=
n = int(input())
h = list(map(int , input().split()))
output = 0
for i in range(n):
if h[i] == 0:
if i == 0:
output += h[1]
elif i == n-1:
output += h[i-1]
else:
if h[i-1] >= h[i+1]:
output += h[i+1]
else:
output += h[i-1]
print(output)
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
int map[n];
for (int i = 0; i < n; i++)
cin >> map[i];
int ans = 0;
if (map[0] == 0)
ans += map[1];
if (map[n-1] == 0)
ans += map[n-2];
for (int i = 1; i < n-1; i++){
if (map[i] == 0)
ans += min(map[i-1] , map[i+1]);
}
cout << ans << endl;
return 0;
}
```
#### [h026. 202001_1 猜拳](https://zerojudge.tw/ShowProblem?problemid=h026)
- python
```python=
f = int(input())
n = int(input())
y = list(map(int, input().split()))
ans = []
num = 0
for i in range(n):
ans.append(f)
# win
if (f, y[i]) in [(0, 2), (2, 5), (5, 0)]:
num = 1
break
# lose
elif (f, y[i]) in [(0, 5), (2, 0), (5, 2)]:
num = 2
break
# drew
else:
if i > 0 and y[i] == y[i-1]:
if y[i] == 0: f = 5
elif y[i] == 2: f = 0
else: f = 2
else: f = y[i]
out = ' '.join(map(str, ans))
if num == 0: print(f"{out} : Drew at round {n}")
elif num == 1: print(f"{out} : Won at round {len(ans)}")
else: print(f"{out} : Lost at round {len(ans)}")
```
- cpp
```cpp=
#include <iostream>
#include <cmath>
using namespace std;
int map[15];
int ans[15]; // 哥拳
int main() {
int f , n , k = 0 ;
int num = 0;//win or lose or drew
cin >> f >> n;
for (int i = 0; i < n; i++)
cin >> map[i];
for (int i = 0; i < n; i++){
ans[k] = f;
k++;
//cout << f;
//win
if ((f == 0 && map[i] == 2) || (f == 2 && map[i] == 5) or (f == 5 && map[i] == 0)){
num++;
break;
}
//lose
else if ((f == 2 && map[i] == 0) || (f == 5 && map[i] == 2) or (f == 0 && map[i] == 5)){
num+=2;
break;
}
//drew
else{
//妹兩次一樣
if (i>0 && map[i] == map[i-1]){
if (map[i] == 0) f = 5;
else if (map[i] == 2) f = 0;
else f = 2;
}
else f == map[i];
}
}
for (int i = 0; i < k;i++)
cout << ans[i] << " ";
if (!num) cout << ": Drew at round " << n;
else if (num == 1) cout << ": Won at round " << k;
else cout << ": Lost at round " << k;
return 0;
}
```
#### [h081. 1. 程式交易](https://zerojudge.tw/ShowProblem?problemid=h081)
- python
```python=
n , d = map(int,input().split())
a = list(map(int , input().split()))
b = a[0]
c = 0
profit = 0
for i in range(n):
if b != 0:
if (a[i] >= d + b):
profit += a[i] - b
c = a[i]
b = 0
else :
if a[i] <= c - d:
b = a[i]
print(profit)
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int n , d;
cin >> n >> d;
int map[n];
for (int i = 0; i < n; i++) cin >> map[i];
int b = map[0] , profit = 0 , c = 0;
for (int i = 1; i < n; i++){
if (b != 0 && map[i] >= b+d)
profit += map[i] - b , b = 0 , c = map[i];
if (!b && c - d >= map[i])
b = map[i];
}
cout << profit;
return 0;
}
```
#### [i399. 1. 數字遊戲](https://zerojudge.tw/ShowProblem?problemid=i399)
- python
```python=
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
if a[0] == a[1] == a[2]: print(3 , a[0])
elif (a[0] == a[1]) or (a[1] == a[2]): print(2 , a[0] , a[2])
else: print(1 , a[0] , a[1] , a[2])
```
- cpp
```cpp=
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
vector<int>map(3);
for (int i = 0; i < 3; i++) cin >> map[i];
sort(map.rbegin() , map.rend());
if (map[0] == map[1] && map[1] == map[2])
printf("3 %d" , map[0]);
else if (map[0] == map[1] || map[1] == map[2])
printf("2 %d %d" , map[0] , map[2]);
else
printf("1 %d %d %d" , map[0] , map[1] , map[2]);
return 0;
}
```
#### [i428. 1. 巴士站牌](https://zerojudge.tw/ShowProblem?problemid=i428)
- python
```python=
n = int(input())
ans = []
x1 , y1 = map(int , input().split())
for i in range(n-1):
x2 , y2 = map(int , input().split())
ans.append(abs(x1-x2) + abs(y1-y2))
x1 , y1 = x2 , y2
print(max(ans) , min(ans))
```
- cpp
```cpp=
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n , x1 , y1;
cin >> n >> x1 >> y1;
vector<int>map;
for (int i = 0; i < n-1; i++){
int x2 , y2;
cin >> x2 >> y2;
map.push_back(abs(x1 - x2) + abs(y1 - y2));
x1 = x2 , y1 = y2;
}
cout << *max_element(map.begin() , map.end()) << " " << *min_element(map.begin() , map.end());
}
```
#### [j605. 1. 程式考試](https://zerojudge.tw/ShowProblem?problemid=j605)
- python
```python=
n = int(input())
tl = []
sl = []
sc = 0
for i in range(n):
t,s = map(int,input().split())
tl.append(t)
sl.append(s)
if s == -1:
sc += 1
ans = max(sl) - n - (sc*2)
if ans < 0:
ans = 0
print(ans,tl[sl.index(max(sl))])
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int a;
int c = -1 , d = -1 , e = 0;
cin >> a;
for (int i = 0; i < a; i++){
int t , s;
cin >> t >> s;
if (s > d) d = s , c = t;
if (s == -1) e+=1;
}
int output = d - a - 2*e;
if (output < 0) output = 0;
cout << output << " " << c;
return 0;
}
```
#### [k731. 1. 路徑偵測](https://zerojudge.tw/ShowProblem?problemid=k731)
- python
```python=
n = int(input())
pre_x , pre_y = map(int , input().split())
direct = 0
pre_dir = 0
left = 0
right = 0
rev = 0
for i in range(n-1):
x , y = map(int , input().split())
if x > pre_x: direct = 0
elif y < pre_y: direct = 1
elif x < pre_x: direct = 2
else: direct = 3
print(f'{direct} ')
if direct == (pre_dir+1)%4: right += 1
elif direct == (pre_dir+2)%4: rev += 1
elif direct == (pre_dir+3)%4: left += 1
pre_dir = direct
pre_x = x
pre_y = y
print(f'{left} {right} {rev}')
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main() {
int n , dir , prev_dir = 0;// first dir = east
int x , y , px , py;
int left = 0 , right = 0 , rev = 0;
cin >> n >> px >> py;
for (int i = 1;i < n; i++) {
cin >> x>> y;
if (x > px) dir = 0; // east
else if (y < py) dir = 1; //south
else if (x < px) dir = 2; //west
else dir = 3; //north
// using dir and prev_dir to determine turn
if (dir == (prev_dir+1)%4) right++;
else if (dir==(prev_dir+2)%4) rev++;
else if (dir==(prev_dir+3)%4) left++;
// else no direction changed
prev_dir = dir;
px = x, py =y;
}
cout << left<<' '<<right<<' '<<rev<<'\n';
return 0;
}
```
#### [m370. 1. 機械鼠](https://zerojudge.tw/ShowProblem?problemid=m931)
- python
```python=
n = int(input())
item = []
dig = []
for i in range(n):
a , b = map(int , input().split())
item.append([a , b])
dig.append(a*a + b*b)
dig[dig.index(max(dig))] = 0
num = dig.index(max(dig))
print(item[num][0] , item[num][1])
```
- cpp
```cpp=
#include <iostream>
#include <cmath>
using namespace std;
int map[25][2];
int sums[25];
int main() {
int n , y;
int suma = 0;
cin >> n;
for (int i = 0 ; i < n ; i++)
for (int j = 0; j < 2; j++)
cin >> map[i][j];
for (int i = 0; i < n; i++){
sums[i] = pow(map[i][0] , 2) + pow(map[i][1] , 2);
if (sums[i] > suma) y = i , suma = sums[i];
}
sums[y] = 0 , suma = 0;
for (int i = 0 ; i < n; i++)
if (sums[i] > suma) y = i , suma = sums[i];
cout << map[y][0] << " " << map[y][1];
return 0;
}
```
#### [m931. 1. 遊戲選角](https://zerojudge.tw/ShowProblem?problemid=m370)
- python1
```python=
n = int(input())
item = []
dig = []
for i in range(n):
a , b = map(int , input().split())
item.append([a , b])
dig.append(a*a + b*b)
dig[dig.index(max(dig))] = 0
num = dig.index(max(dig))
print(item[num][0] , item[num][1])
```
- python2
```python=
l = []
for _ in range(int(input()):
a, b = map(int, input().split())
l.append(a*a+b*b, a, b)
l.sort(key = lambda x : x[0])
print(l[1][1], l[1][2])
```
- cpp
```cpp=
#include <iostream>
#include <cmath>
using namespace std;
int map[25][2];
int sums[25];
int main() {
int n , y;
int suma = 0;
cin >> n;
for (int i = 0 ; i < n ; i++){
for (int j = 0; j < 2; j++)
cin >> map[i][j];
}
for (int i = 0; i < n; i++){
sums[i] = pow(map[i][0] , 2) + pow(map[i][1] , 2);
if (sums[i] > suma) y = i , suma = sums[i];
}
sums[y] = 0 , suma = 0;
for (int i = 0 ; i < n; i++)
if (sums[i] > suma) y = i , suma = sums[i];
cout << map[y][0] << " " << map[y][1];
return 0;
}
```
#### [o076. 1. 特技表演](https://zerojudge.tw/ShowProblem?problemid=o076)
- python
```python=
n = int(input())
a = [int(i) for i in input().split()]
maxs = 1001
ans = 0
num = 0
for i in range(len(a)):
if maxs > a[i]:
num += 1
maxs = a[i]
ans = max(ans , num);
else:
maxs = a[i]
num = 1
print(ans)
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main() {
int n , map[105] , maxs = 1001 , ans = 0 , num = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> map[i];
if (maxs > map[i]) num++ , maxs = map[i] , ans = max(ans , num);
else maxs = map[i] , num = 1;
}
cout << ans;
return 0;
}
```
#### [o711. 1. 裝飲料](https://zerojudge.tw/ShowProblem?problemid=o711)
- python
```python=
n = int(input())
w1 , w2 , h1 , h2 = map(int , input().split())
l = [int(i) for i in input().split()]
maxs = []
v1 , v2 = w1*w1*h1 , w2*w2*h2
for i in l:
total = 0
if v1 - i > 0:
total += i/(w1*w1)
v1 -= i
else:
total += v1/(w1*w1)
i -= v1
v1 = 0
if v2 - i > 0:
total += i/(w2*w2)
v2 -= i
else:
total += v2/(w2*w2)
maxs.append(total)
break
maxs.append(total)
print(int(max(maxs)))
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int n , w1 , w2 , h1 , h2;
cin >> n >> w1 >> w2 >> h1 >> h2;
int l[n];
for (int i = 0; i < n; i++)
cin >> l[i];
int v1 = w1*w1*h1 , v2 = w2*w2*h2 , maxs = 0;
for (auto p : l){
int total = 0;
if (v1 > p)
total += p/(w1*w1) , v1 -= p;
else{
total += v1/(w1*w1) , p -= v1 , v1 = 0;
if (v2 > p)
total += p/(w2*w2) , v2 -= p;
else{
total += v2/(w2*w2) , maxs = max(maxs , total);
break;
}
}
maxs = max(maxs , total);
}
cout << maxs;
return 0;
}
```
#### [q181. 1. 等紅綠燈](https://zerojudge.tw/ShowProblem?problemid=q181)
- python
```python=
a, b = map(int, input().split())
n = int(input())
l = [int(i) for i in input().split()]
sums = 0
for i in l:
if i % (a+b) >= a:
sums += b - (i%(a+b)-a)
print(sums)
```
- cpp
```cpp=
#include <iostream>
using namespace std;
int main(){
int a, b, n, t;
cin >> a >> b >> n;
int sums = 0;
for (int i = 0; i < n; i++){
cin >> t;
if (t % (a+b) >= a)
sums += b - (t%(a+b)-a);
}
cout << sums;
return 0;
}
```