99882024-03-23 15:22:36111Autózáscpp17Runtime error 95/100165ms16932 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct S{
	int d,c,i;
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("be1.txt","r",stdin);
#endif
	int N,K;
	cin>>N>>K;
	deque<S>q;
	map<int,int>m;
	int t=0;
	int ans=0;
	for(int i=1;i<=N;i++){
		int d,c;
		cin>>d>>c;
		while(!q.empty()&&c<q.back().c){
			t-=q.back().d;
			q.pop_back();
		}
		if(t<K){
			q.push_back({K-t,c,i});
		}
		t=K;
		while(q.front().d<=d){
			m[q.front().i]+=q.front().d;
			ans+=q.front().c*q.front().d;
			d-=q.front().d;
			t-=q.front().d;
			q.pop_front();
		}
		if(d>0){
			m[q.front().i]+=d;
			ans+=q.front().c*d;
			q.front().d-=d;
			t-=d;
		}
	}
	cout<<ans<<' '<<m.size()<<'\n';
	for(auto[a,b]:m){
		cout<<a<<' '<<b<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base95/100
1Accepted0/03ms1828 KiB
2Accepted0/063ms2184 KiB
3Runtime error0/53ms2332 KiB
4Accepted5/53ms2592 KiB
5Accepted5/53ms2696 KiB
6Accepted5/53ms2996 KiB
7Accepted5/52ms2996 KiB
8Accepted5/53ms3152 KiB
9Accepted5/53ms3296 KiB
10Accepted5/53ms3148 KiB
11Accepted5/520ms4172 KiB
12Accepted5/532ms4700 KiB
13Accepted5/519ms3576 KiB
14Accepted5/539ms3708 KiB
15Accepted5/596ms12208 KiB
16Accepted5/592ms11660 KiB
17Accepted5/593ms11808 KiB
18Accepted5/589ms11508 KiB
19Accepted5/5148ms15812 KiB
20Accepted5/5155ms16160 KiB
21Accepted5/5159ms16540 KiB
22Accepted5/5165ms16932 KiB