99892024-03-23 15:23:17111Autózáscpp17Accepted 100/100165ms16860 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.empty()&&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(!q.empty()&&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
base100/100
1Accepted0/03ms1828 KiB
2Accepted0/061ms2228 KiB
3Accepted5/53ms2228 KiB
4Accepted5/53ms2444 KiB
5Accepted5/53ms2652 KiB
6Accepted5/53ms2868 KiB
7Accepted5/53ms3080 KiB
8Accepted5/53ms3160 KiB
9Accepted5/53ms3160 KiB
10Accepted5/53ms3164 KiB
11Accepted5/521ms3988 KiB
12Accepted5/532ms4520 KiB
13Accepted5/519ms3532 KiB
14Accepted5/537ms3620 KiB
15Accepted5/596ms12024 KiB
16Accepted5/592ms11576 KiB
17Accepted5/594ms11620 KiB
18Accepted5/589ms11244 KiB
19Accepted5/5150ms15416 KiB
20Accepted5/5153ms16028 KiB
21Accepted5/5162ms16464 KiB
22Accepted5/5165ms16860 KiB