https://i-blog.csdnimg.cn/blog_migrate/ad724a05672fa8246ecdac3691a6cc31.png
Input
Output
Sample Input
3 2 1 2 3 3 2 2 2 2
Sample Output
6 6
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define mod 1000000007
struct p
{
int x;
bool friend operator <(p a,p b)
{
return a.x%3<b.x%3 || a.x%3==b.x%3&&a.x<b.x;
}
};
int main()
{
int n,m;
ll ans,sum;
p t;
while(~scanf("%d %d",&n,&m))
{
priority_queue<p>q;
sum=0;
for(int i=0; i<n; i++)
{
scanf("%d",&t.x);
q.push(t);
sum+=t.x/3+(t.x%3==0?0:1);
}
ans=sum;printf("%lld\n",sum);
while(m--)
{
if(!q.empty())
{
t=q.top();
q.pop();
sum-=t.x/3+(t.x%3==0?0:1);
t.x-=2;
if(t.x>0)
{
sum+=t.x/3+(t.x%3==0?0:1);
q.push(t);
}
ans=(ans+sum)%mod;
}
}
printf("%lld\n",ans);
}
return 0;
}