fork(3) download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <vector>
  10. #include <map>
  11. #include <sstream>
  12. #include <cmath>
  13. #include <limits>
  14. #include <utility>
  15. #include <iomanip>
  16. #include <set>
  17. #include <numeric>
  18. #include <cassert>
  19. #include <ctime>
  20.  
  21. #define INF_MAX 2147483647
  22. #define INF_MIN -2147483647
  23. #define INF_LL 9223372036854775807LL
  24. #define INF 2000000000
  25. #define PI acos(-1.0)
  26. #define EPS 1e-8
  27. #define LL long long
  28. #define mod 1000000007
  29. #define pb push_back
  30. #define mp make_pair
  31. #define f first
  32. #define s second
  33. #define setzero(a) memset(a,0,sizeof(a))
  34. #define setdp(a) memset(a,-1,sizeof(a))
  35. #define bits(a) __builtin_popcount(a)
  36.  
  37. using namespace std;
  38.  
  39. vector<pair<int, int> > a, b;
  40.  
  41. int main()
  42. {
  43. ios_base::sync_with_stdio(0);
  44. //freopen("lca.in", "r", stdin);
  45. //freopen("lca.out", "w", stdout);
  46. int n, x, y;
  47. cin >> n;
  48. for(int i=0;i<n;i++)
  49. {
  50. cin >> x >> y;
  51. if(x < 0) a.pb(mp(x, y));
  52. else b.pb(mp(x, y));
  53. }
  54. sort(a.begin(), a.end(), greater<pair<int, int> >());
  55. sort(b.begin(), b.end());
  56. int res = 0;
  57. if(a.size() == b.size())
  58. {
  59. for(int i=0;i<a.size();i++)
  60. res+=a[i].s + b[i].s;
  61. }
  62. else if(a.size() > b.size())
  63. {
  64. for(int i=0;i<b.size();i++)
  65. res+=a[i].s + b[i].s;
  66. res+=a[b.size()].s;
  67. }
  68. else
  69. {
  70. for(int i=0;i<a.size();i++)
  71. res+=a[i].s + b[i].s;
  72. res+=b[a.size()].s;
  73. }
  74. cout << res;
  75. return 0;
  76. }
Success #stdin #stdout 0s 3236KB
stdin
2
-1 5
1 5
stdout
10