1874A - Jellyfish and Game - CodeForces Solution


brute force games greedy implementation

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n, m, k;
        cin >> n >> m >> k;
        int min_a = 1e9, max_a = 1, min_b = 1e9, max_b = 1;
        long long int sum_a = 0;
        for (int i=0; i<n; i++) {
            int temp;
            cin >> temp;
            sum_a += temp;
            min_a = min_a < temp ? min_a : temp;
            max_a = max_a > temp ? max_a : temp;
        }
        for (int i=0; i<m; i++) {
            int temp;
            cin >> temp;
            min_b = min_b < temp ? min_b : temp;
            max_b = max_b > temp ? max_b : temp;
        }
        
        if (min_a < max_b) {
            sum_a += - min_a + max_b;
            min_b = min(min_a, min_b);
            max_a = max(max_a, max_b);
        }
        if (k&1) cout << sum_a << "\n";
        else {
            if (min_b < max_a) {
                sum_a += min_b - max_a;
            }
            cout << sum_a << "\n";
        }
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

967B - Watering System
152A - Marks
1398A - Bad Triangle
137A - Postcards and photos
1674D - A-B-C Sort
334A - Candy Bags
855A - Tom Riddle's Diary
1417A - Copy-paste
1038A - Equality
1061A - Coins
1676E - Eating Queries
1447A - Add Candies
1721D - Maximum AND
363C - Fixing Typos
1401A - Distance and Axis
658A - Bear and Reverse Radewoosh
1721E - Prefix Function Queries
977E - Cyclic Components
1140D - Minimum Triangulation
75C - Modified GCD
1722A - Spell Check
1722B - Colourblindness
1722D - Line
1722C - Word Game
1722G - Even-Odd XOR
552E - Vanya and Brackets
933A - A Twisty Movement
1722F - L-shapes
1196B - Odd Sum Segments
1325D - Ehab the Xorcist