题解 P6013 【压岁钱】
Suuon_Kanderu
2020-01-28 21:14:35
首先要提醒大家,作为一个普及T1难度的题,还是比较坑的。
大家注意$ \textcolor{white}{
In ,ten, years, OI ,is ,empty. , Without,long long , I, will ,see, my, ancestors.} $
我就因为此错了3+回(太菜)$\color{white}\texttt{十年OI一场空,不开long long 见祖宗}$
没办法,弱就是我的归宿,被大佬暴打就是我的命运~~强行凑字~~$\color{white}\texttt{百度机翻差评}$
,这题,看起来$ int$就够了,但是$m<=5 \times10^6$, $a<=10^7$,这么一乘,$ int $就不负众望的爆了,要开~~龙龙~~long long
这个题还是挺简单的,思路看注释吧。
```
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string.h>
#include <algorithm>
using namespace std;
const long long N=1e6+100;
long long n,ans,sum;// n个事件,钱不够花的事件数,当前的钱数
long long money[N];//在第i个事件将解封a元钱
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
int op,a,b;
sum+=money[i];//在第i个事件能解封a元钱
scanf("%d",&op);
if(op==1){
scanf("%d",&a);
sum+=a; //存a元钱
}
if(op==2){
scanf("%d",&a);
if(a>sum)ans++;//如果钱不够了,ans++
else sum-=a;
}
if(op==3){
scanf("%d%d",&a,&b);
sum-=a;//封印a元钱
money[b]+=a;// 在第b个事件将解封a元钱
}
}
cout<<ans<<endl;
return 0;
}
```
主要针对蒟蒻 $ \textcolor{white}{isn't,me?} $
比较详细,大佬请无视。
$
\color{blue}\texttt{文} \color{green}\texttt{内} \color{silver}\texttt{有} \color{pink}\texttt{彩}\color{purple}\texttt{蛋} \color{orange}\texttt{啊}
$