题意:https://ac.nowcoder.com/acm/contest/1111/D

问你先减二x次的情况下,最少减几次3。

思路:

%3不为0的要先减2,然后%3为0的要先减大的(比如9 3 3 会比3 3 9 更优)

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int ans[N];
void PR(int _[],int n)
{
for(int i=;i<=n;++i)
pr("%d ",_[i]);
pr("\n");
}
priority_queue<int>q,q3;
int main()
{
int n,m;
while(~sc("%d%d",&n,&m))
{
int sum=;
while(!q.empty())q.pop();
while(!q3.empty())q3.pop();
for(int i=;i<=n;++i)
{
int tt;
sc("%d",&tt);
sum+=(tt+)/;
if(tt%==)
q3.push(tt);
else if(tt%==)
q.push(tt);
else if(tt%==)
q.push(tt);
}
ans[]=sum;
for(int i=;i<=m;++i)
{
bool f=;
if(!q.empty())
{
f=;
int tt=q.top();q.pop();
sum--;
if(tt->)
{
tt-=;
if(tt%==)
q3.push(tt);
else
q.push(tt);
}
}
if(!f)
{
if(!q3.empty())
{
int tt=q3.top();q3.pop();
q.push(tt-);
}
}
ans[i]=sum;
}
ll ANS=;
// PR(ans,m);
for(int i=;i<=m;++i)
ANS+=ans[i],ANS%=mod;
pr("%lld\n",ANS);
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

最新文章

  1. LightOj 1298 - One Theorem, One Year(DP + 欧拉)
  2. 导入CSV格式的数据
  3. C#ArrayList集合——小例题
  4. 再谈LRU双链表内存管理
  5. 这些年你需要注意的SQL
  6. java io读书笔记(3)数值类型的数据
  7. Remove Nth Node From End of List [LeetCode]
  8. java窗体与Flash交互
  9. iOS中通知的添加和移除
  10. HDU 4931 Happy Three Friends(水)
  11. leetcode刷题笔记08 字符串转整数 (atoi)
  12. 多线程统计次数问题:即count++
  13. node express 上传文件
  14. python-写入excel(xlswriter)
  15. Linux报错:bash: pip: command not found
  16. OpenCV LK光流法测试
  17. ifconfig 输出里没有IP地址
  18. 20165313 《Java程序设计》第九周学习总结
  19. scrapy 项目通过scrapyd部署
  20. 吴裕雄 实战PYTHON编程(10)

热门文章

  1. AcWing:237. 程序自动分析(离散化 + 并查集)
  2. Spring Cloud Eureka(四):Eureka 配置参数说明
  3. Java并发之ThreadPoolExecutor
  4. JavaScript设计模式—装饰器模式
  5. centos 下启动 rabbitmq 报错的解决
  6. 如何在uboot下列出使用的设备树信息?
  7. Horovod 通信策略
  8. 解决docker命令行终端显示不全的问题
  9. 用es6实现一个promsie
  10. Redis Guide