171082025-05-22 18:51:32algoproAutózáscpp17Wrong answer 17/10064ms8808 KiB
// UUID: d6ddf711-d98e-4d97-a693-3525b2755c33
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define int ll

int n,k,most=0,ossz=0;
vector<int> tav,cost,hol,ki,dp;

signed next(int x)
{
	int remaining=k;
	int legk=x;
	//cerr << tav[x] << "\n";
	while(x>=0 && remaining-tav[x]>0)
	{
		//cerr << "idk ";
		if(cost[x]<cost[legk])
			legk=x;
		remaining-=tav[x];
		x--;
	}
	if(x==-1)
		return 0;
	hol.push_back(next(legk-1));
	return legk;
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	dp.push_back(0);
	for(int i=0; i<n; i++)
	{
		int a,b; cin >> a >> b;
		tav.push_back(a);
		cost.push_back(b);
		dp.push_back(dp.back()+a);
	}
	hol.push_back(next(n-1));
	hol.push_back(n);
	/*for(auto& z:hol)
		cerr << z << " ";
	cerr << "\n";
	for(auto& z:dp)
		cerr << z << " ";*/
	for(int i=0; i<hol.size()-1; i++)
	{
		if(cost[hol[i]]<cost[hol[i+1]])
		{
			ki.push_back(k-most);
			most=k-(dp[hol[i+1]]-dp[hol[i]]);
		}
		else
		{
			ki.push_back(dp[hol[i+1]]-dp[hol[i]]-most);
			most=0;
		}
		ossz+=ki.back()*cost[hol[i]];
	}
	cout << ossz << " " << ki.size() << "\n";
	for(int i=0; i<ki.size(); i++)
		cout << hol[i]+1 << " " << ki[i] << "\n";
}
SubtaskSumTestVerdictTimeMemory
base17/100
1Accepted0/01ms316 KiB
2Wrong answer0/064ms8580 KiB
3Partially correct2/51ms500 KiB
4Accepted5/51ms316 KiB
5Accepted5/51ms316 KiB
6Wrong answer0/51ms316 KiB
7Accepted5/51ms316 KiB
8Wrong answer0/51ms316 KiB
9Wrong answer0/51ms316 KiB
10Wrong answer0/51ms440 KiB
11Wrong answer0/513ms2048 KiB
12Wrong answer0/520ms2896 KiB
13Wrong answer0/517ms2700 KiB
14Wrong answer0/535ms4744 KiB
15Wrong answer0/535ms4744 KiB
16Wrong answer0/535ms4688 KiB
17Wrong answer0/535ms4732 KiB
18Wrong answer0/535ms4496 KiB
19Wrong answer0/554ms8576 KiB
20Wrong answer0/557ms8664 KiB
21Wrong answer0/561ms8808 KiB
22Wrong answer0/561ms8580 KiB