99872024-03-23 15:13:58111Autózáscpp17Runtime error 95/100171ms17692 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("be3.txt","r",stdin);
#endif
	int N,K;
	cin>>N>>K;
	deque<array<int,3>>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()[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){
			m[q.front()[2]]+=q.front()[1];
			ans+=q.front()[0]*q.front()[1];
			d-=q.front()[1];
			t-=q.front()[1];
			q.pop_front();
		}
		m[q.front()[2]]+=d;
		ans+=q.front()[0]*d;
		q.front()[1]-=d;
		t-=d;
	}
	cout<<ans<<' '<<m.size()<<'\n';
	for(auto[a,b]:m){
		cout<<a<<' '<<b<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base95/100
1Accepted0/03ms1824 KiB
2Accepted0/061ms2184 KiB
3Runtime error0/53ms2328 KiB
4Accepted5/53ms2496 KiB
5Accepted5/53ms2656 KiB
6Accepted5/52ms2740 KiB
7Accepted5/53ms2764 KiB
8Accepted5/53ms2972 KiB
9Accepted5/53ms3184 KiB
10Accepted5/53ms3404 KiB
11Accepted5/521ms4408 KiB
12Accepted5/532ms4672 KiB
13Accepted5/519ms3484 KiB
14Accepted5/537ms3496 KiB
15Accepted5/5100ms12196 KiB
16Accepted5/596ms11856 KiB
17Accepted5/597ms12324 KiB
18Accepted5/590ms12024 KiB
19Accepted5/5150ms16360 KiB
20Accepted5/5159ms16760 KiB
21Accepted5/5162ms17100 KiB
22Accepted5/5171ms17692 KiB