-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
106 lines (103 loc) · 2.38 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
long long ara[100005];
int main()
{
fastio;
long long t,n,l,r,i,cnt,cur,lp,rp;
cin>>t;
while(t--)
{
cnt=0;
cur=0; lp=-1; rp=-1;
cin>>n>>l>>r;
for(i=0;i<n;i++)
cin>>ara[i];
for(i=0;i<n;i++)
{
if(cur==0)
{
if(ara[i]<l)
{
cur=ara[i];
lp=i;
rp=i;
}
else if(ara[i]>=l && ara[i]<=r)
{
cnt++;
cur=0;
lp=i;
rp=i;
}
else
{
cur=0;
lp=i;
rp=i;
}
}
else if(cur+ara[i]>=l && cur+ara[i]<=r)
{
cnt++;
cur=0;
lp=i;
rp=i;
}
else if(cur+ara[i]<l)
{
cur+=ara[i];
rp=i;
}
else
{
int f=0;
while(lp!=rp)
{
cur-=ara[lp];
lp++;
if(cur+ara[i]>=l && cur+ara[i]<=r)
{
f=1;
cnt++;
cur=0;
lp=i;
rp=i;
break;
}
else if(cur+ara[i]<l)
{
f=1;
cur+=ara[i];
rp=i;
break;
}
}
if(f==1)
continue;
cur=ara[i];
if(cur>=l && cur<=r)
{
cnt++;
cur=0;
lp=i;
rp=i;
}
else if(cur>r)
{
cur=0;
lp=i;
rp=i;
}
else
{
lp=i;
rp=i;
}
}
}
cout<<cnt<<"\n";
}
return 0;
}