99852024-03-23 15:10:24111Autózáscpp17Runtime error 71/10079ms23888 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("be2.txt","r",stdin);
#endif
	int N,K;
	cin>>N>>K;
	deque<array<int,3>>q;
	vector<pair<int,int>>v;
	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()[0]){
			t-=q.back()[1];
			q.pop_back();
		}
		q.push_back({c,K-t,i});
		t=K;
		while(q.front()[1]<=d){
			ans+=q.front()[0]*q.front()[1];
			if(!v.empty()&&v.back().first==q.front()[2]){
				v.back().second+=q.front()[1];
			}
			else{
				v.push_back({q.front()[2],q.front()[1]});
			}
			d-=q.front()[1];
			t-=q.front()[1];
			q.pop_front();
		}
		ans+=q.front()[0]*d;
		if(!v.empty()&&v.back().first==q.front()[2]){
			v.back().second+=d;
		}
		else{
			v.push_back({q.front()[2],d});
		}
		q.front()[1]-=d;
		t-=d;
	}
	cout<<ans<<' '<<v.size()<<'\n';
	for(auto[a,b]:v){
		cout<<a<<' '<<b<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base71/100
1Accepted0/03ms1828 KiB
2Accepted0/057ms3840 KiB
3Runtime error0/53ms3980 KiB
4Accepted5/53ms3884 KiB
5Accepted5/53ms4120 KiB
6Accepted5/53ms4232 KiB
7Accepted5/53ms4448 KiB
8Accepted5/53ms4536 KiB
9Accepted5/53ms4672 KiB
10Accepted5/53ms4772 KiB
11Accepted5/514ms5684 KiB
12Accepted5/521ms6664 KiB
13Accepted5/518ms6468 KiB
14Accepted5/535ms7604 KiB
15Partially correct2/550ms12932 KiB
16Partially correct2/546ms12004 KiB
17Partially correct2/548ms13352 KiB
18Partially correct2/546ms14520 KiB
19Partially correct2/571ms18008 KiB
20Partially correct2/574ms19940 KiB
21Partially correct2/575ms21980 KiB
22Partially correct2/579ms23888 KiB