[codeforces1070C]Cloud Computing
time limit per test : 3 seconds
memory limit per test : 256 megabytes
Buber is a Berland technology company that specializes in waste of investor’s money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n
consecutive days, which are numbered from 1 to n. Buber requires k
CPU cores each day.
The cloud provider offers m
tariff plans, the
tariff plan is characterized by the following parameters:
and
— the
tariff plan is available only on days from
to
, inclusive,
— the number of cores per day available for rent on the
tariff plan,
— the price of renting one core per day on the
tariff plan.
Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to
) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day.
Find the minimum amount of money that Buber will pay for its work for days from to . If on a day the total number of cores for all available tariff plans is strictly less than , then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly cores this day.
Input
The first line of the input contains three integers
,
and
— the number of days to analyze, the desired daily number of cores, the number of tariff plans.
The following
lines contain descriptions of tariff plans, one description per line. Each line contains four integers
, where
and
are starting and finishing days of the
tariff plan,
— number of cores,
— price of a single core for daily rent on the
tariff plan.
Output
Print a single integer number — the minimal amount of money that Buber will pay.
Examples
Input
5 7 3
1 4 5 3
1 3 5 2
2 5 10 1
Output
44
Input
7 13 5
2 3 10 7
3 5 10 10
1 2 10 6
4 5 10 9
3 4 10 8
Output
462
Input
4 100 3
3 3 2 5
1 1 3 2
2 4 4 4
Output
64
題意:
有
種借用雲端計算核心的方案,第
種方案由
,
,
,
來描述。
表示這種方案的可借用時間是從第
天到第
天,每天這種方案提供至多
個核心,每個核心所要的租金是
公司在這
天內,每天如果能租到的核心個數小於
,則全部租掉,否則租剛好
個核心,請問過完這
天,公司最少要花掉多少錢。
題解:
差分+線段樹。
對於每一個核心使用方案分成(
,
,
)和(
,
,
)兩個方案,記為對
有影響和對
有影響。
然後順著從
到
掃一遍,對每個點插入所有有影響該點的方案。然後查詢整個線段樹,計算當前點的最小答案,這個只需要一個線段樹查詢即可,線段樹每個結點記錄當前單價在
到
的核心的數量,還有總價格。
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
#define pa pair<int,int>
using namespace std;
int n,ks,m;
vector<pa>oc[1000004];
struct tree{
int l,r;
ll cn,cm;
}tr[4000004];
void build(int k,int l,int r){
tr[k].cn=0;tr[k].cm=0;
tr[k].l=l;tr[k].r=r;
if(l==r)return ;
int mid=(l+r)>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
}
void add(int k,int c,int p){
int l=tr[k].l,r=tr[k].r;
tr[k].cn+=c