#include <bits/stdc++.h>
using namespace std;
#define nd second
#define st first
int n;
map<pair<int,pair<int,int>>, int>m;
map<int,pair<int,int>>cnt;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(); cout.tie();
cin>>n;
for(int i=0; i<n; i++){
int type, w, t;
cin>>type>>w>>t;
if(type==1)
m[{type-1, {w, -t}}]++;
else
m[{type-1, {-t, w}}]++;
}
int cost=0;
for(auto a:m){
auto key=a.st;
int x=key.nd.st, y=key.nd.nd;
cost+=a.nd-1;
if(key.st==0) cnt[x+y].st++;
else cnt[x+y].nd++;
}
for(auto a:cnt){
cost+=min(a.nd.st, a.nd.nd);
}
cout<<cost;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <bits/stdc++.h> using namespace std; #define nd second #define st first int n; map<pair<int,pair<int,int>>, int>m; map<int,pair<int,int>>cnt; int main(){ ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin>>n; for(int i=0; i<n; i++){ int type, w, t; cin>>type>>w>>t; if(type==1) m[{type-1, {w, -t}}]++; else m[{type-1, {-t, w}}]++; } int cost=0; for(auto a:m){ auto key=a.st; int x=key.nd.st, y=key.nd.nd; cost+=a.nd-1; if(key.st==0) cnt[x+y].st++; else cnt[x+y].nd++; } for(auto a:cnt){ cost+=min(a.nd.st, a.nd.nd); } cout<<cost; return 0; } |
English