Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define F first
  4. #define S second
  5. #define pb push_back
  6. #define ll long long
  7. #define ld long double
  8. #define FILE "answer"
  9. #define pii pair <int,int>
  10.  
  11. using namespace std;
  12.  
  13. const int mod = 1e9 + 7;
  14. const int INF = 1e9;
  15.  
  16. int res[100005];
  17. pair <int,int> a[100005];
  18. set <pair <int,int> > st;
  19.  
  20. int main() {
  21. ios_base::sync_with_stdio(0);
  22. cin.tie(0);
  23. cout.tie(0);
  24. // freopen("input.txt","r",stdin);
  25. // freopen("output.txt","w",stdout);
  26. int n, m;
  27. cin >> n >> m;
  28. for (int i = 0; i < m; i++) {
  29. cin >> a[i].F >> a[i].S;
  30. st.insert({a[i].F, a[i].S});
  31. }
  32. ll ans = 0;
  33. while (n--) {
  34. pair <int,int> cur = *st.rbegin();
  35. st.erase(cur);
  36. ans += cur.F;
  37. res[cur.S]++;
  38. cur.F = max(0, cur.F - a[cur.S].S);
  39. st.insert(cur);
  40. }
  41. cout << ans << endl;
  42. for (int i = 0; i < n; i++) {
  43. cout << res[i] << " ";
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement