99862024-03-23 15:11:20111Autózáscpp17Runtime error 71/10079ms7476 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();
		}
		if(t<K){
			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/057ms2208 KiB
3Runtime error0/53ms2204 KiB
4Accepted5/53ms2356 KiB
5Accepted5/52ms2416 KiB
6Accepted5/53ms2540 KiB
7Accepted5/52ms2632 KiB
8Accepted5/52ms2632 KiB
9Accepted5/53ms2756 KiB
10Accepted5/53ms2860 KiB
11Accepted5/514ms3228 KiB
12Accepted5/521ms3528 KiB
13Accepted5/518ms2852 KiB
14Accepted5/535ms2976 KiB
15Partially correct2/550ms7184 KiB
16Partially correct2/546ms5136 KiB
17Partially correct2/548ms5168 KiB
18Partially correct2/546ms5108 KiB
19Partially correct2/571ms7476 KiB
20Partially correct2/575ms7396 KiB
21Partially correct2/579ms7396 KiB
22Partially correct2/579ms7392 KiB