setpresetion @ 2024-01-29 14:21:26
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,i,j,k,maxn=0,f[1001000],ok[1000100];
struct node{
int s,t,w;
}a[1001000];
bool valid(int x){
memset(f,0,sizeof(f));
for(i=1;i<=x;++i){
f[a[i].s]+=a[i].w;
f[a[i].t+1]-=a[i].w;
}
j=0;
for(i=1;i<=n;++i){
j+=f[i];
if(j>ok[i])return false;
}
return true;
}
int main(){
memset(f,0,sizeof(f));
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)scanf("%d",&ok[i]);
for(i=1;i<=m;++i)scanf("%d%d%d",&a[i].w,&a[i].s,&a[i].t);
if(valid(m)){printf("0\n");return 0;}
int l=1,r=m;
while(l<r){
int mid=(l+r)/2;
if(valid(mid)) l=mid+1;
else r=mid;
}
printf("-1\n%d\n",l);
return 0;
}
结果是20分: | wa | tle |
---|---|---|
re | ac | |
wa | wa | |
tle | tle | |
ac | wa |
by xiaoshumiao @ 2024-01-29 14:22:38
@rickyxue 你确定你没发错题?这是“借教室”那题的代码啊。
by setpresetion @ 2024-01-29 14:30:41
@xiaoshumiao 那也有一个是WA啊,帮一下也可以
by xiaoshumiao @ 2024-01-29 14:36:50
@rickyxue 鉴定为没开 long long。
by HenryQ2022 @ 2024-01-30 16:20:53
输入都错了
by yinjiayu @ 2024-01-31 20:29:33
6
by zhanghr12 @ 2024-02-04 16:16:32
需要这么麻烦吗?用cin、cout不就轻松过了。
by zhanghr12 @ 2024-02-04 16:17:39
代码:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
c=a+b;
cout<<c;
return 0;
}
by SamShang @ 2024-02-05 13:32:42
@zhanghr12 你说的很好
by RaymondOccam @ 2024-02-17 15:41:02
@xiaoshumiao
int上限是
by xiaoshumiao @ 2024-02-17 15:41:49
@mini123 不懂别瞎说。
我说的是,“借教室”那题需要开 long long。