Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solve() {
- ll n, m;
- std::cin >> n >> m;
- std::vector<std::pair<ll, ll>> pc, tc;
- ll p[n + m + 2], t[n + m + 2];
- for (ll i = 1; i <= n + m + 1; i++) {
- std::cin >> p[i];
- }
- for (ll i = 1; i <= n + m + 1; i++) {
- std::cin >> t[i];
- }
- for (ll i = 1; i <= n + m + 1; i++) {
- if (p[i] > t[i]) {
- pc.push_back({p[i], i});
- } else {
- tc.push_back({t[i], i});
- }
- }
- std::vector<ll> ans(n + m + 2);
- ll fin = 0;
- if (pc.size() > n) {
- for (ll i = 0; i < n; i++) fin += pc[i].first;
- for (ll i = n; i < pc.size(); i++) fin += t[pc[i].second];
- for (ll i = 0; i < tc.size(); i++) fin += tc[i].first;
- for (ll i = 0; i < n; i++) {
- ans[pc[i].second] = fin - pc[i].first + pc[n].first - t[pc[n].second];
- }
- for (ll i = n; i < pc.size(); i++) {
- ans[pc[i].second] = fin - t[pc[i].second];
- }
- for (ll i = 0; i < tc.size(); i++) {
- ans[tc[i].second] = fin - tc[i].first;
- }
- } else {
- for (ll i = 0; i < m; i++) fin += tc[i].first;
- for (ll i = m; i < tc.size(); i++) fin += p[tc[i].second];
- for (ll i = 0; i < pc.size(); i++) fin += pc[i].first;
- for (ll i = 0; i < m; i++) {
- ans[tc[i].second] = fin - tc[i].first + tc[m].first - p[tc[m].second];
- }
- for (ll i = m; i < tc.size(); i++) {
- ans[tc[i].second] = fin - p[tc[i].second];
- }
- for (ll i = 0; i < pc.size(); i++) {
- ans[pc[i].second] = fin - pc[i].first;
- }
- }
- for (ll i = 1; i <= n + m + 1; i++) {
- std::cout << ans[i] << " \n"[i == n + m + 1];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement