Advertisement
Emiliatan

e197

Jul 23rd, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. /* e197             */
  2. /* AC (0.2s, 884KB) */
  3. #pragma warning( disable : 4996 )
  4. #include <cstdio>
  5. #include <functional>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. typedef pair<int, int> pii;
  11.  
  12. constexpr int MAXM = 1e5 + 1;
  13. int T, N, M;
  14. long long ans;
  15. pair<int, int> d[MAXM];
  16.  
  17. int main()
  18. {
  19.     scanf("%d", &T);
  20.     while (T--)
  21.     {
  22.         ans = 0;
  23.         scanf("%d %d", &N, &M);
  24.  
  25.         for (int i = 0; i < M; ++i)
  26.             scanf("%d", &d[i].first);
  27.  
  28.         for (int i = 0; i < M; ++i)
  29.             scanf("%d", &d[i].second);
  30.  
  31.         sort(d, d + M, greater<pii>());
  32.  
  33.         for (int i = 0; i < M; ++i)
  34.             if (d[i].second > 0)
  35.             {
  36.                 ans += ((d[i].second >> 1) + (d[i].second & 0x1)) * d[i].first;
  37.                 d[i + 1].second -= (d[i].second & 0x1);
  38.             }
  39.  
  40.         printf("%lld\n", ans << 1);
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement