题意
两排物品摆放,每个物品有价格和高度两个属性
要求:
- each前排高度小于后排
- 行内价格从左到右不下降
solution
首先每行按价格排序
每行将价格相同的放进buffer
。
固定buffer.size()
小的那个然后用另一个buffer
贪心的取同等价格可以取的高度里最大的。
buffer
空了适时补充
“能犯的错误都犯了一遍”
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
struct Node{
int idx, price, height;
Node (){}
Node (int id, int p, int h):idx(id), price(p), height(h){}
friend bool operator < (const Node &a,const Node &b){
return a.height < b.height;
}
void print(){
printf("Node %d: p = %d, h = %d\n", idx, price, height);
}
}fro[N], bac[N];
bool cmp (const Node &a,const Node &am