【踏前斩】请问各位大佬看看我这题思路哪里有问题,不知道为啥只过了20% public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] strs = br.readLine().split(" "); br.close(); int[] nums = new int[n]; for(int i = 0; i < n; i++) { nums[i] = Integer.parseInt(strs[i]); } int cnt = 0; for(int i = n - 2; i >= 0; i--) { int a = nums[i], b = nums[i + 1] / 2, c = nums[i + 2] / 3; if(a > 0 &;&; b > 0 &;&; c > 0) { int t = Math.min(a, Math.min(b, c)); cnt += 5 * t; nums[i] -= t; nums[i + 1] -= 2 * t; nums[i + 2] -= 3 * t; } } for(int i = 0; i < n; i++) cnt += nums[i]; System.out.println(cnt); } }
点赞 评论

相关推荐

牛客网
牛客企业服务