题解:P13797 [SWERC 2023] Programming-trampoline-athlon!

· · 题解

题目传送门

思路解析

struct QWQ { string code; int total; int idx; };

bool cmp(const QWQ &a, const QWQ &b) { if(a.total != b.total) return a.total > b.total; return a.idx < b.idx; }

int main() { int n; cin >> n; vector<QWQ> lzy(n);

for(int i=0;i<n;i++)
{
    int p,sum=0;
    cin >> lzy[i].code >> p;
    lzy[i].idx=i;

    vector<int> e(6);
    for(int j=0;j<6;j++)
        cin >> e[j];

    sort(e.begin(),e.end());
    for(int j=1;j<=4;j++)
        sum+=e[j];

    lzy[i].total=p*10+sum;
}

sort(lzy.begin(),lzy.end(),cmp);

vector<QWQ> medal;
for(int i=0;i<n && medal.size() < 1000;i++)
{
    int cnt=0;
    for(int j=0;j<n;j++)
    {
        if(lzy[j].total > lzy[i].total)
        {
            cnt++;
            if(cnt > 2)
                break;
        }
    }

    if(cnt <= 2)
        medal.push_back(lzy[i]);
    else
        break;
}

for(auto &t : medal)
    cout << t.code << " " << t.total << "\n";

return 0;

}