Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- ll mod = 1e9 + 7;
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- ll t;
- cin >> t;
- while (t--)
- {
- ll n, m;
- cin >> n >> m;
- map<ll, vector<ll>> coins;
- for (int i = 0; i < m; i++)
- {
- ll d, v;
- cin >> d >> v;
- coins[d].push_back(v);
- }
- ll effi = n;
- ll ans = 0;
- priority_queue<ll> currCoins;
- for (int i = 0; i < n; i++)
- {
- for (auto i : coins[i + 1])
- {
- currCoins.push(i);
- }
- if (!currCoins.empty())
- {
- ll val = currCoins.top();
- currCoins.pop();
- ans += effi * val;
- }
- effi--;
- }
- cout << ans << "\n";
- }
- return 0;
- }
- //--------------------------------------------------------------------------------------
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- ll mod = 1e9 + 7;
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- ll t;
- cin >> t;
- while (t--)
- {
- ll n, m;
- cin >> n >> m;
- map<ll, vector<ll>> coins;
- for (int i = 0; i < m; i++)
- {
- ll d, v;
- cin >> d >> v;
- coins[d].push_back(v);
- }
- vector<pair<ll, vector<ll>>> coinsArray;
- for (auto i : coins)
- {
- coinsArray.push_back(i);
- }
- ll effi = n;
- ll ans = 0;
- priority_queue<ll> currCoins;
- for (int i = 0; i < coinsArray.size(); i++)
- {
- for (auto j : coinsArray[i].second)
- {
- currCoins.push(j);
- }
- if (i != coinsArray.size() - 1)
- {
- ll len = coinsArray[i + 1].first - coinsArray[i].first;
- ll reduceNum = 0;
- while (len && !currCoins.empty())
- {
- ll curr = currCoins.top();
- currCoins.pop();
- ans += effi * curr;
- effi--;
- reduceNum++;
- len--;
- }
- effi -= coinsArray[i + 1].first - coinsArray[i].first - reduceNum;
- }
- }
- ll leftLen = n - coinsArray[coinsArray.size() - 1].first + 1;
- while (leftLen && !currCoins.empty())
- {
- ll curr = currCoins.top();
- currCoins.pop();
- ans += curr * effi;
- effi--;
- leftLen--;
- }
- cout << ans << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement