Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- #include <random>
- using namespace std;
- const int SIZE = 251;
- const int FUNC = 50;
- int64_t table[FUNC][SIZE];
- vector<pair<int, int>> seed;
- int get_hash(int id, int64_t a, int64_t b) {
- return (a + b * id) % SIZE;
- }
- int main() {
- int n;
- cin >> n;
- std::random_device rd;
- std::mt19937 gen(rd());
- std::uniform_int_distribution<int> dist(100000, numeric_limits<int>::max());
- for (int i = 0; i < n; ++i) {
- int id, pay;
- cin >> id >> pay;
- for (int j = 0; j < FUNC; ++j) {
- int a = dist(gen);
- int b = dist(gen);
- seed.push_back({a, b});
- table[j][get_hash(id, a, b)] += pay;
- }
- }
- int card;
- cin >> card;
- int64_t ans = numeric_limits<int64_t>::max();
- for (int i = 0; i < FUNC; ++i) {
- int a = seed[i].first;
- int b = seed[i].second;
- int hash = get_hash(card, a, b);
- for (int j = 0; j < SIZE; ++j) {
- ans = min(ans, table[i][hash]);
- }
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement