弄一个优先队列,每次取出最小的,然后和s时间比较,加上t时间就是答案。。。。简单贪心


#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 1000005
#define maxm 2000005
#define eps 1e-9
#define mod 1000000007
#define INF 0x3f3f3f3f
#define PI (acos(-1.0))
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid 
#define rson o<<1 | 1, mid+1, R
#define pii pair<int, int>
#pragma comment(linker, "/STACK:16777216")
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
//head

priority_queue<LL, vector<LL>, greater<LL> > q;
int n, m;

void read()
{
	scanf("%d%d", &n, &m);
}

void work()
{
	LL s, t;
	for(int i = 1; i <= m; i++) q.push(0);
	for(int i = 1; i <= n; i++) {
		scanf("%I64d%I64d", &s, &t);
		LL tt = q.top();
		q.pop();
		tt = max(tt, s);
		tt += t;
		printf("%I64d\n", tt);
		q.push(tt);
	}
}

int main()
{
	read();
	work();
	
	return 0;
}