170532025-05-20 17:48:25algoproAutózáscpp17Wrong answer 17/100173ms12856 KiB
// UUID: 28e0d285-20a9-42ea-ab02-6846f0848c58
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed 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,  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/0142ms12084 KiB
3Runtime error0/51ms316 KiB
4Accepted5/51ms316 KiB
5Partially correct2/51ms316 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Wrong answer0/51ms380 KiB
9Wrong answer0/51ms316 KiB
10Wrong answer0/51ms356 KiB
11Wrong answer0/529ms2612 KiB
12Wrong answer0/546ms4044 KiB
13Wrong answer0/543ms3792 KiB
14Wrong answer0/586ms7416 KiB
15Wrong answer0/5104ms7988 KiB
16Wrong answer0/5101ms7680 KiB
17Wrong answer0/5104ms7732 KiB
18Wrong answer0/596ms7476 KiB
19Wrong answer0/5153ms11572 KiB
20Wrong answer0/5162ms12084 KiB
21Wrong answer0/5173ms12584 KiB
22Wrong answer0/5170ms12856 KiB