题目链接:点击进入
题目
思路
贪心排序
因为 20 ^ 20 会爆 long long ,用__int128代替(我主要想强调__int128!!)
代码
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define base 131
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define lowbit(x) x & -x
#define inf 0x3f3f3f3f
//#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-7;
const double pai=acos(-1.0);
const int N=2e4+10;
const int maxn=1e6+10;
const int mod=998244353;
int t,n,m,ans;
bool vis[maxn];
struct node
{
__int128 a;
__int128 b;
}p[maxn];
inline __int128 read()
{
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void write(__int128 x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
bool cmp(node e,node f)
{
return e.a*f.b+e.b<f.a*e.b+f.b;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);cout.tie(0);
cin>>n;
__int128 x=read();
for(int i=1;i<=n;i++)
{
p[i].a=read();
p[i].b=read();
}
sort(p+1,p+n+1,cmp);
for(int i=1;i<=n;i++)
x=p[i].a*x+p[i].b;
write(x);
return 0;
}