招行信用卡中心笔试大数据第一题

同输入输出问题。。。。第一题两个测试用例全过了,提交为0%
寻求热心小伙伴指点。感谢!!

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Long> out = new ArrayList<>();
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            Long[] a = new Long[n + 1];
            Long[] b = new Long[n];
            for (int i = 0; i <= n; i++) {
                a[i] = sc.nextLong();
            }
            for (int i = 0; i < n; i++) {
                b[i] = sc.nextLong();
            }
            out.add(solution(n, a, b));
        }

        for (Long line : out) {
            System.out.println(line);
        }
    }
    private static Long solution(int n, Long[] a, Long[] b) {
        Long out = 0l;
        for (int i = 0; i < n; i++) {
            Long ai = a[i];
            Long next = a[i + 1];
            Long bi = b[i];
            if (bi >= ai) {
                out += ai;
                bi = bi - ai;
                if (bi >= next) {
                    out += next;
                    a[i + 1] = 0l;
                } else {
                    out += bi;
                    a[i + 1] = a[i + 1] - bi;
                }
            }
        }
        return out;
    }
}


#招商银行##笔试题目##Java##秋招#
全部评论
我都是0,楼主第二题多少
点赞 回复
分享
发布于 2019-09-15 22:58
这个题是不是要考虑从两端向中间靠的情况啊,虽然最后改了一下还是没过。。
点赞 回复
分享
发布于 2019-09-15 23:11
博乐游戏
校招火热招聘中
官网直投
我记得昨天晚上,有个牛油给了关于输入输出的教程,怎么今早就没了?
点赞 回复
分享
发布于 2019-09-16 09:25
37行是什么意思01
点赞 回复
分享
发布于 2019-09-16 10:10
代码写错了,a[i + 1] = a[i + 1] - bi;
点赞 回复
分享
发布于 2019-09-16 10:12
我也是,本地测试样例都过了,结果0%
点赞 回复
分享
发布于 2019-09-16 15:02

相关推荐

点赞 6 评论
分享
牛客网
牛客企业服务