大奋场,T3 没切有点菜
Rank
A. 草莓
和前天多校 T3 很像,所以一眼鉴定为贪心,从大到小选比从小到大选一眼优,代价一样时横竖无所谓先后,然后 sort 一遍就做完了,复杂度 \((n+m)\log(n+m)\)。10min 切的。
点击查看代码
#include<bits/stdc++.h>
#define fo(x,y,z) for(register int (x) = (y);(x)<=(z);(x)++)
#define fu(x,y,z) for(register int (x) = (y);(x)>=(z);(x)--)
using namespace std;
typedef long long ll;
#define lx ll
inline lx qr()
{
char ch = getchar();lx x = 0 , f = 1;
for(;ch<'0'||ch>'9';ch = getchar()) if(ch == '-') f = -1;
for(;ch>= '0' && ch<= '9';ch = getchar()) x = (x<<3) + (x<<1) + (ch^48);
return x*f;
}
#undef lx
#define qr qr()
#define fi first
#define se second
#define P_B(x) push_back(x)
#define pii pair<int , int>
const int Ratio = 0;
const int N = 2e5 + 5;
int n, m;
pii a[N << 1];
ll ans;
namespace Wisadel
{
short main()
{
freopen("guiltiness.in", "r", stdin) , freopen("guiltiness.out", "w", stdout);
n = qr, m = qr;
int tot = n + m - 2;
fo(i, 1, n - 1) a[i].fi = qr, a[i].se = 1;
fo(i, 1, m - 1) a[n - 1 + i].fi = qr, a[n + i].se = 2;
sort(a + 1, a + 1 + tot, [](pii A, pii B){return A.fi > B.fi;});
int timn = 0, timm = 0;
fo(i, 1, tot)
{
int zc = (a[i].se == 1 ? timm : timn) + 1;
ans += 1ll * a[i].fi * zc;
a[i].se == 1 ? timn++ : timm++;
}
printf("%lld\n", ans);
return Ratio;
}
}
signed main(){return Wisadel::main();}
为什么强调 10min 切的
标签:ch,int,ll,qr,NOIP2024,加赛,mod,模拟,fo From: https://www.cnblogs.com/Ratio-Yinyue1007/p/18553723