How to take out the data of the top few

there is a problem in my work. Two arrays of infinite length, A & M B, have a similar structure as follows:

{
    a:2,
    b:3,
    c:4,
    d:5
    ...
}
{
    b:1,
    c:5,
    e:3,
    ...
}

needs to combine the data of the top 10 with the largest amount of data added together (for example, the top 10), but because the two arrays of memory space cannot be added directly, only part of the data can be sorted and then added and compared. So is there an algorithm that can implement this problem?

Mar.31,2021

according to your needs, ask a question:
Why can't large wireless arrays be solved directly with the database

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3aa25-2b777.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3aa25-2b777.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?