170522025-05-20 17:47:27algoproAutózáscpp17Wrong answer 17/100166ms7152 KiB
// UUID: 49e1ca75-18a0-4af6-b184-7a8236062f11
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> d(n), c(n), dp(n), prefix(n+1);
	for(int i=0;i<n;i++) cin >> d[i] >> c[i];
	for(int i=1;i<=n;i++) prefix[i]=prefix[i-1]+d[i-1];
	deque<int> dq;
	int gas=0;
	long long cost=0;
	vector<int> capacity(n, k);
	for(int i=0;i<n;i++){
		while(!dq.empty() && c[i]<c[dq.back()]) dq.pop_back();
		while(!dq.empty() && k<prefix[i]-prefix[dq.front()]) dq.pop_front();
		dq.push_back(i);
		bool repeat=true;
		int dist=d[i];
		while(repeat){
			repeat=false;
			gas-=d[i];
			int amount=min(capacity[dq.front()], min(k-gas, dist));
			dist-=amount;
			capacity[dq.front()]-=amount;
			cost+=amount*c[dq.front()];
			gas+=amount;
			//cout << dq.front() << ' ' << amount << '\n';
			if(capacity[dq.front()]<=0){
				dq.pop_front();
				repeat=true;
			}
		}
	}
	int tankNum=0;
	for(int x : capacity) tankNum+=(x<k);
	cout << cost << ' ' << tankNum << '\n';
	for(int i=0;i<n;i++) if(capacity[i]<k) cout << i+1 << ' ' << k-capacity[i] << '\n';
}
SubtaskSumTestVerdictTimeMemory
base17/100
1Accepted0/01ms316 KiB
2Wrong answer0/0140ms6196 KiB
3Runtime error0/51ms316 KiB
4Accepted5/51ms316 KiB
5Partially correct2/51ms368 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Wrong answer0/51ms316 KiB
9Wrong answer0/51ms316 KiB
10Wrong answer0/51ms316 KiB
11Wrong answer0/528ms1616 KiB
12Wrong answer0/546ms2108 KiB
13Wrong answer0/541ms2096 KiB
14Wrong answer0/583ms3796 KiB
15Wrong answer0/5103ms4404 KiB
16Wrong answer0/597ms4148 KiB
17Wrong answer0/5101ms4404 KiB
18Wrong answer0/593ms4092 KiB
19Wrong answer0/5150ms6436 KiB
20Wrong answer0/5157ms6600 KiB
21Wrong answer0/5160ms6760 KiB
22Wrong answer0/5166ms7152 KiB