Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- #define pb push_back
- #define ll long long
- #define ld long double
- #define FILE "answer"
- #define pii pair <int,int>
- using namespace std;
- const int mod = 1e9 + 7;
- const int INF = 1e9;
- int res[100005];
- pair <int,int> a[100005];
- set <pair <int,int> > st;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- int n, m;
- cin >> n >> m;
- for (int i = 0; i < m; i++) {
- cin >> a[i].F >> a[i].S;
- st.insert({a[i].F, a[i].S});
- }
- ll ans = 0;
- while (n--) {
- pair <int,int> cur = *st.rbegin();
- st.erase(cur);
- ans += cur.F;
- res[cur.S]++;
- cur.F = max(0, cur.F - a[cur.S].S);
- st.insert(cur);
- }
- cout << ans << endl;
- for (int i = 0; i < n; i++) {
- cout << res[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement