3368. 逃课吃鸡

Saitama
#include <bits/stdc++.h>

using namespace std;

typedef struct{string s; int len;}zz;

bool cmp(const zz &x, const zz &y)
{
    if(x.s != y.s)
        return x.s < y.s;
    else
        return x.len > y.len;
}

int main()
{
    int n;
    cin >> n;
    vector <zz> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i].s >> a[i].len;
    sort(a.begin(), a.end(), cmp);
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        if(i >= 2)
            if(a[i].s == a[i - 1].s && a[i].s == a[i - 2].s)
                continue;

        sum += a[i].len;
    }
    cout << sum << endl;
    return 0;
}
我太难了
#include <bits/stdc++.h>
using namespace std;

int main()
{
    map<string, vector<int>> p;
    int n, x;
    cin >> n;
    string s;
    int sum = 0;
    while(n--){
        cin >> s >> x;
        p[s].push_back(x);
    }
    for(auto it:p){
        sort(it.second.begin(), it.second.end(), greater<int>());
        if(it.second.size()>=2)
            sum += it.second[0] + it.second[1];
        else
            sum += it.second[0];
    }
    cout << sum;
    return 0;
}
你当前正在回复 博客/题目
存在问题!