#include using namespace std; #define int long long #define app push_back #ifndef LOCAL #define endl '\n' #endif // LOCAL typedef long long ll; struct Line { ll k, b; Line() : k(), b() {} Line (ll _k, ll _b) : k(_k), b(_b) {} ll getVal(ll x) { return k * x + b; } }; ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up struct Hull { vector lines; vector borders; Hull() : lines(), borders() {} void addLine(Line L) { while(!lines.empty()) { if (lines.back().getVal(borders.back()) >= L.getVal(borders.back())) { lines.pop_back(); borders.pop_back(); } else break; } if (lines.empty()) { lines.push_back(L); borders.push_back(0LL); //leftmost query return; } if (lines.back().k <= L.k) return; ll x = div_up(L.b - lines.back().b, lines.back().k - L.k); //must work for negative! lines.push_back(L); borders.push_back(x); } ll getMinVal(ll x) { int pos = upper_bound(borders.begin(), borders.end(), x) - borders.begin(); if (pos == 0) throw; pos--; return lines[pos].getVal(x); } }; Hull c; vector slv1(vector > a,int m) { set > d; vector answ={0}; if(a.empty()) {for(int i=0;i slv2(vector > v,int m) { if(v.empty()) {vector answ;for(int i=0;i<=m;++i) answ.push_back((i!=0)*(-1e18)); return answ;} vector > l; for(auto [a,d]:v) { l.push_back({-d,-2*a+d}); } sort(l.begin(),l.end());reverse(l.begin(),l.end()); for(auto [k,b]:l) { c.addLine(Line(k,b)); } vector res; for(int i=0;i<=m;++i) { int ans=-c.getMinVal(i); ans*=i;assert(ans%2==0);ans/=2; res.push_back(ans); } return res; } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,m;cin>>n>>m; vector > v1,v2; for(int i=0;i>x>>y;if(y<=0) {v1.push_back({x,y});} else {v2.push_back({x,y});}} vector res1=slv1(v1,m);vector res2=slv2(v2,m); //for(int x:res1) cout<