Codeforces Round 920 (Div. 3)
A. Square
#include<bits/stdc++.h>
using namespace std;
void solve(){
int a1,b1,a2,b2,a3,b3,a4,b4;
cin>>a1>>b1>>a2>>b2>>a3>>b3>>a4>>b4;
int s1,s2;
if(a1==a2){
s1=abs(b1-b2);
s2=abs(b3-b4);
}else if(a1==a3){
s1=abs(b1-b3);
s2=abs(b2-b4);
}else if(a1==a4){
s1=abs(b1-b4);
s2=abs(b2-b3);
}
int ans=s1*s2;
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
B. Arranging Cats
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n;
string s1,s2;
cin>>n>>s1>>s2;
int cnt1=0,cnt2=0;
for(int i=0;i<n;i++){
if(s1[i]=='1'&&s2[i]=='0')cnt1++;
if(s2[i]=='1'&&s1[i]=='0')cnt2++;
}
int ans=min(cnt1,cnt2)+(max(cnt1,cnt2)-min(cnt1,cnt2));
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
C. Sending Messages
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int p[N];
void solve(){
int n,k,a,b;
cin>>n>>k>>a>>b;
int f=0;
for(int i=1;i<=n;i++)cin>>p[i];
for(int i=1;i<=n;i++){
int x=p[i]-p[i-1];
if(x*a>b)k-=b;
else k-=x*a;
if(k<=0){
f=1;
}
}
if(k<=0)f=1;
if(f){
cout<<"NO\n";
}else {
cout<<"YES\n";
}
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
D. Very Different Array 贪心+枚举位置
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int a[N],b[N];
void solve(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>b[i];
sort(a+1,a+1+n);
sort(b+1,b+1+m,greater<int>());
int ans=0;
for(int i=1;i<=n;i++){
if(abs(a[i]-b[i])<abs(a[i]-b[m-n+i])){
ans+=abs(a[i]-b[m-n+i]);
}else{
ans+=abs(a[i]-b[i]);
}
}
cout<<ans<<"\n";
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}