fork(4) download
  1. #pragma comment(linker,"/STACK:100000000000,100000000000")
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <algorithm>
  7. #include <string>
  8. #include <cstring>
  9. #include <vector>
  10. #include <cmath>
  11. #include <map>
  12. #include <stack>
  13. #include <set>
  14. #include <iomanip>
  15. #include <queue>
  16. #include <map>
  17. #include <functional>
  18. #include <memory.h>
  19. #include <list>
  20. #include <sstream>
  21. #include <ctime>
  22. #include <climits>
  23. #include <bitset>
  24. #include <list>
  25. #include <cassert>
  26. #include <complex>
  27.  
  28. using namespace std;
  29.  
  30. /* Constants begin */
  31. const long long inf = 1e18+7;
  32. const long long mod = 1e9+7;
  33. const double eps = 1e-12;
  34. const double PI = 2*acos(0.0);
  35. const double E = 2.71828;
  36. /* Constants end */
  37.  
  38. /* Defines begin */
  39. #define pb push_back
  40. #define mp make_pair
  41. #define ll long long
  42. #define double long double
  43. #define F first
  44. #define S second
  45. #define all(a) (a).begin(),(a).end()
  46. #define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
  47. #define random (rand()<<16|rand())
  48. #define sqr(x) (x)*(x)
  49. #define base complex<double>
  50. /* Defines end */
  51.  
  52. vector<pair<ll,ll> > q;
  53.  
  54. multiset<ll> S;
  55.  
  56. int main(void) {
  57. #ifndef ONLINE_JUDGE
  58. freopen("input.txt","rt",stdin);
  59. freopen("output.txt","wt",stdout);
  60. #endif
  61. int n, k; scanf("%d%d",&n,&k);
  62. q.resize(n);
  63. ll res = 0;
  64. forn(i,n){
  65. int a, b; scanf("%d%d",&a,&b);
  66. q[i] = mp(b,a);
  67. res += b;
  68. }
  69. sort(all(q));
  70. reverse(all(q));
  71. forn(i,k){
  72. int a; scanf("%d",&a);
  73. S.insert(a);
  74. }
  75. forn(i,q.size()){
  76. set<ll> :: iterator it = S.lower_bound(q[i].S);
  77. if(it == S.end()){
  78. res -= q[i].F;
  79. } else {
  80. S.erase(it);
  81. }
  82. }
  83. cout << res << endl;
  84. return 0;
  85. }
  86.  
Runtime error #stdin #stdout #stderr 0s 3480KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_fill_insert