Submission #1311497

#TimeUsernameProblemLanguageResultExecution timeMemory
1311497thuhienneShopping Plans (CCO20_day2problem3)C++20
Compilation error
0 ms0 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() {
	// 1. Sort mỗi vector good[i]
// 2. Tạo vector chứa cặp {good[i][1]-good[i][0], i} và sort theo hiệu số
// 3. PQ lưu: {tổng_hiện_tại, idx_trong_danh_sách_đã_sort, idx_phần_tử_trong_nhóm}

while(pq.size() && print.size() < k) {
    auto [val, i, j] = pq.top(); pq.pop();
    print.push_back(val);

    // Tăng phần tử trong nhóm hiện tại
    if (j + 1 < groups[i].size()) 
        pq.push({val + groups[i][j+1] - groups[i][j], i, j + 1});

    // Thử nhóm tiếp theo
    if (i + 1 < m) {
        // Nhánh mới: Thêm phần tử thứ 2 của nhóm tiếp theo
        pq.push({val + groups[i+1][1] - groups[i+1][0], i + 1, 1});
        // Nhánh "đổi vai": Bỏ phần tử thứ 2 nhóm i, thay bằng phần tử thứ 2 nhóm i+1
        if (j == 1) 
            pq.push({val - (groups[i][1] - groups[i][0]) + (groups[i+1][1] - groups[i+1][0]), i + 1, 1});
    }
}
}

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();

}

Compilation message (stderr)

Main.cpp: In function 'void djt()':
Main.cpp:28:7: error: 'pq' was not declared in this scope
   28 | while(pq.size() && print.size() < k) {
      |       ^~
Main.cpp:33:17: error: 'groups' was not declared in this scope
   33 |     if (j + 1 < groups[i].size())
      |                 ^~~~~~
Main.cpp:39:24: error: 'groups' was not declared in this scope
   39 |         pq.push({val + groups[i+1][1] - groups[i+1][0], i + 1, 1});
      |                        ^~~~~~