169572025-05-19 17:04:32algoproAutózáscpp17Wrong answer 25/100137ms19864 KiB
// UUID: 303dd114-208f-487a-b255-0c92c17c590c
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n; cin>>n;
	int k; cin>>k;
	vector<int> kov(n),ar(n);
	for(int i=0; i<n; i++)
		cin>>kov[i]>>ar[i];
	priority_queue<array<int, 3>> q;
	vector<int> hany(n);
	int ans=0;
	for(int i=0; i<n; i++)
	{
		q.push({-ar[i],k,i});
		int kell=kov[i];
		while(kell>0)
		{
			auto [x,y,ind]=q.top();
			//cout<<x<<" "<<y<<" "<<ind<<endl;
			x=abs(x);
			if(y>kell)
			{
				y-=kell;
				hany[ind]+=kell;
				ans+=x*kell;
				kell=0;
				q.pop();
				q.push({-x,y,ind});
			}
			else
			{
				hany[ind]+=y;
				ans+=y*x;
				kell-=y;
				q.pop();
			}
		}
	}
	vector<array<int, 2>> s;
	for(int i=0; i<n; i++)
		if(hany[i]>0) s.push_back({i+1,hany[i]});
	cout<<ans<<" "<<s.size()<<"\n";
	for(auto &[a,b]:s)
		cout<<a<<" "<<b<<"\n";
}
SubtaskSumTestVerdictTimeMemory
base25/100
1Accepted0/01ms508 KiB
2Wrong answer0/0137ms19864 KiB
3Accepted5/51ms316 KiB
4Accepted5/51ms316 KiB
5Accepted5/51ms316 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Wrong answer0/51ms316 KiB
9Wrong answer0/51ms500 KiB
10Wrong answer0/51ms316 KiB
11Wrong answer0/526ms3336 KiB
12Wrong answer0/543ms5800 KiB
13Wrong answer0/541ms5568 KiB
14Wrong answer0/582ms10824 KiB
15Wrong answer0/578ms10908 KiB
16Wrong answer0/575ms10708 KiB
17Wrong answer0/575ms10772 KiB
18Wrong answer0/571ms10628 KiB
19Wrong answer0/5125ms19108 KiB
20Wrong answer0/5128ms19256 KiB
21Wrong answer0/5127ms19668 KiB
22Wrong answer0/5130ms19824 KiB