QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#257964 | #5549. Game Show | hank55663# | WA | 1ms | 7732kb | C++14 | 2.0kb | 2023-11-19 14:02:48 | 2023-11-19 14:02:49 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define pdd pair<double,double>
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
LL prea[400005],preb[400005];
int a[400005],b[400005];
void solve(int T){
int n,q;
scanf("%d %d",&n,&q);
prea[0]=preb[0]=0;
for(int i = 1;i<=n;i++){
scanf("%d",&a[i]);
prea[i]=prea[i-1]+a[i];
}
for(int i = 1;i<=n;i++){
scanf("%d",&b[i+1]);
}
b[1]=b[n+1];
for(int i = 1;i<=n;i++)printf("%d ",b[i]);
printf("\n");
for(int i = 1;i<=n;i++){
preb[i]=preb[i-1]+b[i];
}
for(int i = n+1;i<=2*n;i++){
prea[i]=prea[i-1]+a[i-n];
preb[i]=preb[i-1]+b[i-n];
}
if(prea[n]<0||preb[n]<0){
for(int i = 0;i<q;i++)printf("flawed\n");
}
else{
for(int i = 1;i<=n;i++){
if(a[i]+(b[(i%n+1)])<0){
for(int i = 0;i<q;i++)printf("flawed\n");
return;
}
}
for(int i=0;i<q;i++){
int s,t;
scanf("%d %d",&s,&t);
if(s==t)printf("0\n");
else {
LL a,b;
if(s>t){
// t+=n;
a=prea[t+n-1]-prea[s-1];
}
else{
a=prea[t-1]-prea[s-1];
}
if(s<t){
b=preb[s+n]-preb[t];
}
else{
b=preb[s]-preb[t];
}
printf("%lld\n",min(a,b));
}
}
}
}
int main(){
int t=1;
//scanf("%d",&t);
for(int i = 1;i<=t;i++){
// cerr<<i<<endl;
solve(i);
}
}
/*
1227076727
1919786269
1261786217
1924134973
1051246577
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7732kb
input:
4 4 2 3 -4 3 1 2 7 -1 1 3 3 1 1 4 1 1
output:
-1 1 2 7 5 -1 -1 0
result:
wrong answer 1st lines differ - expected: '5', found: '-1 1 2 7 '