B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))

题目链接 http://codeforces.com/contest/961/problem/B

我的思路是、t数组为1的就是一定能获得的定理数、我在输入的时候单独的把可以直接听得到的定理数统计出来、

对于需要刺激才能听得到的、我将t数组用一个类收集起来、按时间排序、(找最长子区间)

package acm_2018_04_04;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class B {

    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static String next() throws IOException {
        in.nextToken();
        return (String) in.sval;
    }

    static Node node[] = new Node[100005];
    static int a[] = new int[100005];
    static int n, k;

    public static void main(String[] args) throws IOException {
        for (int i = 0; i < 100005; i++) {
            node[i] = new Node();
        }
        n = nextInt();
        k = nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            a[i] = nextInt();
        }
        int tmp;
        int num = 0;
        for (int i = 1; i <= n; i++) {
            tmp = nextInt();
            if (tmp == 1) {
                sum += a[i];
            } else {
                node[num].time = i;
                node[num++].num = a[i];
            }
        }

        long ans = 0, maxAns = 0;
        int flag = 0;
        if (k > 0) {
            for (int i = 0; i < num; i++) {
                if (k > node[i].time - node[flag].time) {
                    ans += node[i].num;
//                    out.println("增加:" + node[i].time + "时间、讲解的定理数量:" + node[i].num);
                } else {
                    ans -= node[flag].num;
//                    out.println("减少:" + node[flag].time + "时间、讲解的定理数量:" + node[flag].num);
                    flag++;  // 指向尾巴的指针+1,
                    i--; // for里面i++、头结点就不会变 (减少的情况下)
                }
//                out.println("ans = " + ans);
                maxAns = Math.max(ans, maxAns);
            }
        }

        out.println(maxAns + sum);
        out.flush();

    }

    static class Node {

        int time, num; //在 第 time 分钟 讲解的定理数量、、

        public Node() {
        }

        public Node(int time, int num) {
            this.time = time;
            this.num = num;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值