代码:
#include<bits/stdc++.h> using namespace std; #define ll long long #define ls rt<<1,l,m #define rs rt<<1|1,m+1,r #define pb push_back #define mem(a,b) memset((a),(b),sizeof(a)) const int INF=0x3f3f3f3f; const int N=105; struct lesson { string s; int v; operator < (const lesson &t) const { return v>t.v; } }a[N]; map<string,int>mp; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin>>t; while(t--) { mp.clear(); int n; cin>>n; for(int i=0;i<n;i++)cin>>a[i].s>>a[i].v; sort(a,a+n); int ans=0; for(int i=0;i<n;i++) { if(mp[a[i].s]<2) { ans+=a[i].v; mp[a[i].s]++; } } cout<<ans<<endl; } return 0; }
时间: 2024-12-25 07:50:21