Dev Skill How Lazy One can be Part 2
// Accepted
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
const int mod = 1000007;
const int high = 1e5 + 5;
const int inf = 1000000;
LL ar[high];
int main()
{
int i , j , N , test , tc=0;
LL S;
sf("%d", &test);
while(test--)
{
sf("%d %lld", &N , &S);
for(i=0; i<N; i++)
{
sf("%lld", &ar[i]);
}
LL sum=0;
int cnt = inf;
//outn(cnt);
for(i=0; i<N-1; i++)
{
sum = ar[i];
for(j=i+1; j<N; j++)
{
sum += ar[j];
if(sum >= S)
{
int range = ( j - i ) + 1;
//cout << "range=" << range << "; ";
cnt = min(cnt , range);
break;
}
}
}
if(cnt == inf) cnt = -1;
pf("Case %d: %d\n", ++tc , cnt);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
const int mod = 1000007;
const int high = 1e5 + 5;
const int inf = 1000000;
LL ar[high];
int main()
{
int i , j , N , test , tc=0;
LL S;
sf("%d", &test);
while(test--)
{
sf("%d %lld", &N , &S);
for(i=0; i<N; i++)
{
sf("%lld", &ar[i]);
}
LL sum=0;
int cnt = inf;
//outn(cnt);
for(i=0; i<N-1; i++)
{
sum = ar[i];
for(j=i+1; j<N; j++)
{
sum += ar[j];
if(sum >= S)
{
int range = ( j - i ) + 1;
//cout << "range=" << range << "; ";
cnt = min(cnt , range);
break;
}
}
}
if(cnt == inf) cnt = -1;
pf("Case %d: %d\n", ++tc , cnt);
}
return 0;
}
Comments
Post a Comment