题目链接 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;
}
}
}