142372025-01-10 10:19:30tamasmarkDarabolás (50 pont)cpp17Időlimit túllépés 10/50287ms3640 KiB
// darabolas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;
struct adat
{
    unsigned long long  ertek, ered;

};
deque<adat>x,y;
unsigned long long n, m, j, i, sum;

bool hasonlit(adat a, adat b)
{
    if (a.ertek > b.ertek) return 1;
    else return 0;
}
int main()
{
    cin >> n >> m;
    x.resize(n);
    y.resize(m);

    for (i = 1; i < n; ++i)
    {
        cin >> x[i].ered;
        x[i].ertek = x[i].ered;
    }
    for (i = 1; i < m; ++i)
    {
        cin >> y[i].ered;
        y[i].ertek = y[i].ered;
    }
    x.pop_front();
    y.pop_front();
    sort(x.begin(), x.end(),hasonlit);
    sort(y.begin(),y.end(),hasonlit);
    sum = 0;

    while (!x.empty() && !y.empty())
    {

        if (x.front().ertek==y.front().ertek)
        {
            if (x.size() <= y.size())
            {
                sum += x.front().ertek;
                for (auto& e : y)
                    e.ertek += e.ered;
                x.pop_front();
            }
            else
            {
                sum += y.front().ertek;
                for (auto& e : x)
                    e.ertek += e.ered;
                y.pop_front();
            }
        }
        else if (x.front().ertek > y.front().ertek)
        {
            sum += x.front().ertek;
            for (auto& e : y)
                e.ertek += e.ered;
            x.pop_front();
        }
        else
        {
            sum += y.front().ertek;
            for (auto& e : x)
                e.ertek += e.ered;
            y.pop_front();
        }
    }
    while (!x.empty())
    {
        sum += x.front().ertek;
        x.pop_front();
    }
    while (!y.empty())
    {
        sum += y.front().ertek;
        y.pop_front();
    }
    cout << sum;
    return 0;
}
/*
4 6
4 1 2
2 1 3 1 4


*/
// 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base10/50
1Elfogadva0/01ms316 KiB
2Időlimit túllépés0/0286ms2100 KiB
3Elfogadva1/11ms316 KiB
4Elfogadva1/11ms316 KiB
5Elfogadva1/12ms316 KiB
6Elfogadva1/12ms316 KiB
7Elfogadva1/11ms316 KiB
8Elfogadva1/11ms316 KiB
9Elfogadva1/11ms316 KiB
10Elfogadva1/11ms340 KiB
11Elfogadva1/11ms316 KiB
12Elfogadva1/11ms316 KiB
13Hibás válasz0/11ms500 KiB
14Hibás válasz0/12ms316 KiB
15Hibás válasz0/12ms316 KiB
16Hibás válasz0/12ms316 KiB
17Hibás válasz0/13ms316 KiB
18Hibás válasz0/13ms508 KiB
19Hibás válasz0/23ms500 KiB
20Hibás válasz0/23ms500 KiB
21Hibás válasz0/330ms564 KiB
22Hibás válasz0/3111ms564 KiB
23Időlimit túllépés0/4273ms1076 KiB
24Időlimit túllépés0/4275ms1076 KiB
25Időlimit túllépés0/4280ms2100 KiB
26Időlimit túllépés0/4287ms2100 KiB
27Időlimit túllépés0/4282ms3636 KiB
28Időlimit túllépés0/4287ms3640 KiB