#include<iostream>
using namespace std;
#include<queue>
typedef long long ll;
ll fun(ll k,ll b,ll x)
{
return k*x*x+b*x;
}
ll delty(ll k,ll b,ll x)
{
return fun(k,b,x+1)-fun(k,b,x);
}
struct node
{
ll k,b,x;
bool operator<(const node& other)const
{
return delty(k,b,x)<delty(other.k,other.b,other.x);
}
};
priority_queue<node> q;
int main()
{
ll sum=0,n,m,k,b;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>k>>b;
q.push(node{k,b,0});
}
for(int i=1;i<=n;i++)
{
node p=q.top();
q.pop();
if(delty(p.k,p.b,p.x)<=0)
{
break;
}
q.push(node{p.k, p.b, p.x + 1});
}
while(q.size())
{
node p=q.top();
q.pop();
sum+=fun(p.k,p.b,p.x);
}
cout<<sum;
return 0;
}
1 回复
0 转发
1 喜欢
0 阅读



