2020-12-12

qaq学到了学到了…

#include<bits/stdc++.h>
using namespace std;
int n;
pair<long long, long long> num[100010];
priority_queue<long long, vector<long long>, greater<long long> > q;
int main() {
    cin>>n;
    for(int i = 0; i<n; i++) cin>>num[i].first >> num[i].second;
    sort(num, num+n);
    long long now = num[0].second;
    long long summary = num[0].second;
    long long cnt = 0;
    q.push(num[0].first + num[0].second);
    for(int i = 1; i<n; i++) {
        now = now - (num[i].first - num[i-1].first)*(i-cnt) + num[i].second;
        while(q.size() > 0 && q.top() < num[i].first) {
            now+=num[i].first - q.top();
            cnt++;
            q.pop();
        }
        summary = max(summary, now);
        q.push(num[i].first + num[i].second);
    }
    cout<<summary<<endl;
    return 0;
}


# include <iostream>
# include <algorithm>
# define N 1000000

using namespace std;

long long ans=0;
long long a[N+10],d[N+100];

int main(void) {
	for (int i=0; i<(N+10); i++)
		a[i] = d[i] = 0;
	long long n;
	cin>>n;
	long long x, y;
	for (long long i=1; i<=n; i++) {
		cin>>x>>y;
		a[x] += y;
		d[x+1]--;
		long long r = min((long long)(N+10),x+y+1);
		d[r]++;
	}
	long long count = 0;
	long long now = 0;
	for (int i=1; i<=N; i++) {
		count+=d[i];
		now+=a[i];
		now+=count;
		ans = max(ans,now);
	}
	cout<<ans<<endl;
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值