B. I Hate 1111
思路1:可以打表前5000个数 可以猜测1099是最后一个无法表示的数,那么前1100个直接暴力判断,后边的输出YES,可以发现ac了~
思路2:
分析每个全1的数
111=11∗10+1,多出来了1,很麻烦,接着搞
1111=11∗100+11,可以
11111=11∗1000+11∗10+1,又多出来了1?那岂不是可以转化?于是转化为111 ∗ 100 + 11 111 * 100 + 11111∗100+11
111111=11∗10000+11∗100+11
1111111=111∗10000+11∗100+11
可以发现问题就是求解 11∗a+111∗b=X 有没有解
C1. Potions (Easy Version)
反悔贪心
#include<bits/stdc++.h>
using namespace std;
priority_queue <int> q;
int n, x;
int main()
{
cin >> n;
long long sum = 0, ans = 0;
for(int i = 1; i <= n; ++i)
{
cin >> x;
if(x >= 0) sum += x, ++ans;
else
{
if(sum + x >= 0)
q.push(-x), sum += x, ++ans;
else
{
if(!q.empty() && q.top() >= (-x))
{
sum += q.top();
q.pop();
sum += x;
q.push(-x);
}
}
}
}
cout << ans << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int i,j,k,n,m,t,res;
ll tmp;
priority_queue<int> q;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&k);
tmp+=k;
res++;
q.push(-k);
while(tmp<0){
res--;
tmp+=q.top();q.pop();
}
}
printf("%d",res);
}