AcWing 301. 任务安排2
作者:互联网
题目链接
https://www.acwing.com/problem/content/303/
题解
AC代码
import java.util.*;
public class Main {
static int N = (int) 3e5 + 10;
static long[] sumT = new long[N], sumC = new long[N];
static long[] f = new long[N];
static int[] q = new int[N];
static int n, s;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
s = sc.nextInt();
for (int i = 1; i <= n; i ++) {
sumT[i] = sumT[i - 1] + sc.nextInt();
sumC[i] = sumC[i - 1] + sc.nextInt();
}
int hh = 0, tt = 0;
q[0] = 0;
for (int i = 1; i <= n; i ++) {
while (hh < tt && (f[q[hh + 1]] - f[q[hh]]) <= (s + sumT[i]) * (sumC[q[hh + 1]] - sumC[q[hh]])) hh ++;
int j = q[hh];
f[i] = f[j] - sumC[j] * (s + sumT[i]) + s * sumC[n] + sumT[i] * sumC[i];
while (hh < tt && (double) (f[q[tt]] - f[q[tt - 1]]) * (sumC[i] - sumC[q[tt]])
>=
(double) (f[i] - f[q[tt]]) * (sumC[q[tt]] - sumC[q[tt - 1]])) tt --;
q[++ tt] = i;
}
System.out.println(f[n]);
}
}
标签:int,301,tt,安排,long,static,new,sumC,AcWing 来源: https://www.cnblogs.com/doubest/p/16388928.html