# CF #437

http://codeforces.com/contest/867

## B. Save the problem!

Code：

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int main(){
int n;
scanf("%d",&n);
if(n==1) printf("1 1\n1\n");
else
printf("%d 2\n1 2\n",(n-1)*2);
}

## C. Ordering Pizza

pizza个数 = (si)/S$(\sum s_i) / S$

（pizza个数最多变大1，并且A、B剩下的块数之和一定<=S）

Code：

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 200005;

ll n,S,ans,tot,num,tota,totb;
ll s[N],a[N],b[N];
vector<pll> A, B;

int main(){
freopen("3.in","r",stdin);
scanf("%lld%lld",&n,&S);
for(ll i=1;i<=n;i++){
scanf("%lld%lld%lld",s+i,a+i,b+i);
tot+=s[i];
}
num=(tot-1)/S+1;
for(ll i=1;i<=n;i++){
if(a[i]>b[i]){
A.push_back(make_pair(a[i]-b[i],s[i]));
ans+=a[i]*s[i]; tota+=s[i];
}
else{
B.push_back(make_pair(b[i]-a[i],s[i]));
ans+=b[i]*s[i]; totb+=s[i];
}
}
if((tota-1)/S+1 + (totb-1)/S+1 == num) printf("%lld\n",ans);
else{
sort(A.begin(),A.end());
sort(B.begin(),B.end());
// A->B
ll ans1=ans; ll cha=tota%S;
for(ll i=0;cha;i++){
ll x=min(cha,A[i].second);
ans1-=A[i].first*x; cha-=x;
}
// B->A
ll ans2=ans; cha=totb%S;
for(ll i=0;cha;i++){
ll x=min(cha,B[i].second);
ans2-=B[i].first*x; cha-=x;
}
printf("%lld\n",max(ans1,ans2));
}
}

## E. Buy Low Sell High

STL·堆

1. x<堆顶：直接insert(x)
2. 否则，ans+=x-堆顶，弹出堆顶，insert两次x

Code：

#include <iostream>
#include <cstring>
#include <cstdio>
#include <set>
using namespace std;

int n,x; long long ans;
multiset<int> s;

int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&x);
if(!s.empty() && *s.begin() < x){
ans+=x-*s.begin();
s.erase(s.begin());
s.insert(x); s.insert(x);
}
else s.insert(x);
}
printf("%lld\n",ans);
}

#### cf 437 D(并查集)

2016-07-12 19:22:26

#### uva 437 - The Tower of Babylon(DAG最长路)

2013-08-12 13:15:36

#### [python]leetcode(437). Path Sum III

2017-09-15 09:55:43

#### uva437 - The Tower of Babylon（DAG上的DP）

2014-08-06 20:55:03

#### Leetcode 437. Path Sum III 路径和3 解题报告

2016-10-23 14:29:28

#### android string.xml 中显示特殊符号

2015-06-24 13:02:50

#### 常见HTTP状态码返回值大全

2016-11-18 17:46:54

#### SetConsoleOutputCP函数笔记

2018-04-08 12:03:26

#### 代码页即地狱

2014-07-01 15:56:08

#### CF #437 A. Between the Offices【字符串匹配】

2017-10-21 10:11:17