本地通过,ide通过,但是#4死活过不去
查看原帖
本地通过,ide通过,但是#4死活过不去
501470
_299817_楼主2023/1/20 00:15

第4个点T飞了,其他点全部A

下了数据,本地、ide全部不会T

输入:

4
2 2 2 2

输出:

4

我的代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<unordered_map>
#include<map>
#include<queue>
#define sort stable_sort
#define map unordered_map
// #define int long long
using namespace std;
typedef long long ll;

int n;
int a[10000010];
int t[100010];
queue <ll> q1;
queue <ll> q2;
ll ans;
ll x, y;

//注意!用了快读就不能用 freopen !!!
inline void read(int &quick_read1){
    int quick_read2 = 1;
    quick_read1 = 0;
    char quick_read3 = getchar();
    while(quick_read3 < '0' || quick_read3 > '9'){
        if(quick_read3 == '-'){
            quick_read2 = -1;
            quick_read3 = getchar();
        }
    }
    while(quick_read3 >= '0' && quick_read3 <= '9'){
        quick_read1 = quick_read1 * 10 + quick_read3 - '0';
        quick_read3 = getchar();
    }
    quick_read1 *= quick_read2;
}

void Sort(){
    for(int i = 1; i <= n; i++){
        t[a[i]]++;
    }
    for(int i = 1; i <= 100000; i++){
        while(t[i] != 0){
            q1.push(i);
            t[i]--;
        }
    }
}

signed main(){
    read(n);
    for(int i = 1; i <= n; i++){
        read(a[i]);
    }
    Sort();
    for(int i = 1; i < n; i++){
        x = 0, y = 0;
        if(q2.empty() == 1 || (q1.empty() == 0 && q1.front() < q2.front())){
            x = q1.front();
            q1.pop();
        }else{
            x = q2.front();
            q2.pop();
        }
        if(q2.empty() == 1 || (q1.empty() == 0 && q1.front() < q2.front())){
            y = q1.front();
            q1.pop();
        }else{
            y = q2.front();
            q2.pop();
        }
        ans += (x + y);
        q2.push(x + y);
    }
    printf("%lld \n", ans);
    return 0;
}
2023/1/20 00:15
加载中...