标签:image += int color inf import col string scan
题意:略
思路:每一个i号英雄,尽自己所能消灭最多能消灭的怪物即可。
踩坑点:消灭的怪物数量可能超出了整形(int)范围,所以不应该使用int,而应该使用long。这题和四渠注水问题类似,我再一次踩坑。发篇博客警示自己,不要再犯这种低级错误!
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int a[] = new int[n + 1]; int b[] = new int[n]; for (int i = 0; i < n + 1; i++) { a[i] = in.nextInt(); } for (int i = 0; i < n; i++) { b[i] = in.nextInt(); } long ans = 0; for (int i = 0; i < n; i++) { if (b[i] >= a[i]) { ans += a[i]; b[i] -= a[i]; } else { ans += b[i]; b[i] = 0; } if (b[i] >= a[i + 1]) { ans += a[i + 1]; b[i] -= a[i + 1]; a[i + 1] = 0; } else { ans += b[i]; a[i + 1] -= b[i]; b[i] = 0; } } System.out.println(ans); in.close(); } }
标签:image += int color inf import col string scan
原文地址:https://www.cnblogs.com/kyrie211/p/11257670.html