[USACO09MAR]Sand Castle

时间:2023-03-09 15:37:38
[USACO09MAR]Sand Castle

嘟嘟嘟

太水了,大佬们就绕道吧……

就是m, b数组分别排个序,然后更改对应位置的m[i]和b[i],就行了。

因为如果m[i]不改为b[i]而是b[i + 1]的话,那么必定要将m[j] (j > i)改为b[i],而这一定比m[i]改为b[i]更劣。

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a) memset(a, 0, sizeof(a))
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 2.5e4 + ;;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, x, y;
int m[maxn], b[maxn];
ll ans = ; int main()
{
n = read(); x = read(); y = read();
for(int i = ; i <= n; ++i) m[i] = read(), b[i] = read();
sort(m + , m + n + ); sort(b + , b + n + );
for(int i = ; i <= n; ++i) ans += (m[i] - b[i]) * (m[i] > b[i] ? y : -x);
write(ans); enter;
return ;
}