Submission #1311488

#TimeUsernameProblemLanguageResultExecution timeMemory
1311488thuhienneShopping Plans (CCO20_day2problem3)C++20
0 / 25
4100 ms263984 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define re exit(0);

int n,m,k;

vector <int> good[200009];
pair <int,int> lim[200009];

vector <ll> print;

struct temptation {
	int type,pos;
	ll cost;
	const bool operator < (const temptation & other) const {
		return cost > other.cost;
	}
};

void djt() {
	priority_queue <temptation> pq;
	
	ll temp = 0;
	for (int i = 1;i <= m;i++) {
		if (good[i].empty()) {
			for (int j = 1;j <= k;j++) cout << -1 << '\n';
			re;
		}
		temp += good[i][0];
	}
	
	print.push_back(temp);
	
	pq.push({1,1,temp});
	
	while (pq.size()) {
		int type = pq.top().type,pos = pq.top().pos;
		ll cost = pq.top().cost;
		
		pq.pop();
		
		if (pos != 1) print.push_back(cost);
		
		if (type < m) {
			pq.push({type + 1,1,cost});
		}
		
		if (pos < good[type].size()) {
			pq.push({type,pos + 1,cost + good[type][pos] - good[type][pos - 1]});
		}
		
	}
	
	while (print.size() < k) print.push_back(-1);
	for (int i = 0;i < k;i++) cout << print[i] << '\n';
	
}

int main() {
  ios_base::sync_with_stdio(0);cin.tie(nullptr);

	cin >> n >> m >> k;
	for (int i = 1;i <= n;i++) {
		int a,c;cin >> a >> c;
		good[a].push_back(c);
	}
	for (int i = 1;i <= m;i++) cin >> lim[i].first >> lim[i].second;
	
	for (int i = 1;i <= m;i++) sort(good[i].begin(),good[i].end());
	
	djt();

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...