201082026-01-01 21:20:14szabelrDarabolás (50 pont)cpp17Accepted 50/5039ms1224 KiB
// Darabolás.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int m, n;
    cin >> m >> n;
    vector<int> s1(m-1, 0);
    vector<int> s2(n-1, 0);
    long long s1_sum = 0, s2_sum = 0;
    for (int i = 0; i < m - 1; i++)
    {
        int x;
        cin >> x;
        s1[i] = x;
        s1_sum += x;
    }
    for (int i = 0; i < n - 1; i++)
    {
        int x;
        cin >> x;
        s2[i] = x;
        s2_sum += x;
    }
    sort(s1.rbegin(), s1.rend());
    sort(s2.rbegin(), s2.rend());
    int i = 0, y = 0;
    long long sum = 0;
    while (i < s1.size() or y < s2.size())
    {
        if (y >= s2.size() or (s1[i] > s2[y] and i<s1.size()))
        {
            sum += s1[i] + s2_sum;
            s1_sum -= s1[i];
            i++;
        }
        else
        {
            sum += s2[y] + s1_sum;
            s2_sum -= s2[y];
            y++;
        }
    }
    cout << sum;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms508 KiB
2Accepted0/021ms1004 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted1/11ms316 KiB
6Accepted1/11ms316 KiB
7Accepted1/11ms560 KiB
8Accepted1/11ms316 KiB
9Accepted1/11ms316 KiB
10Accepted1/11ms316 KiB
11Accepted1/11ms316 KiB
12Accepted1/11ms316 KiB
13Accepted1/11ms564 KiB
14Accepted1/12ms540 KiB
15Accepted1/11ms316 KiB
16Accepted1/11ms316 KiB
17Accepted1/11ms316 KiB
18Accepted1/12ms316 KiB
19Accepted2/21ms316 KiB
20Accepted2/21ms384 KiB
21Accepted3/33ms316 KiB
22Accepted3/34ms324 KiB
23Accepted4/410ms748 KiB
24Accepted4/410ms564 KiB
25Accepted4/421ms820 KiB
26Accepted4/421ms740 KiB
27Accepted4/439ms1040 KiB
28Accepted4/439ms1224 KiB