/***
Md. Nazmul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include <iomanip>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
#define lowest_int -2147483647
int main()
{
int test, n,p,x;
int petrol[200040];
sc("%d",&test);
int cs=1;
while(test--)
{
sc("%d",&n);
for(int i=1 ; i<=n ; i++)
{
sc("%d",&petrol[i]);
petrol[n+i] = petrol[i];
}
for(int i=1 ; i<=n ; i++)
{
sc("%d",&x);
petrol[i] -= x;
petrol[n+i] -= x;
}
petrol[0] =0;
for(int i=1 ; i<=2*n ; i++)
{
petrol[i] += petrol[i-1];
}
int s=0, mi=1,cnt=0;
for(int i=0 ; i<=2*n ; i++)
{
if(petrol[i]>=mi)
{
if(++cnt>n)
break;
}
else
{
mi = petrol[i];
s= i;
cnt=1 ;
if(i>=n)
break;
}
}
if(cnt>n)
pf("Case %d: Possible from station %d\n",cs++,s+1);
else
pf("Case %d: Not possible\n",cs++);
}
}
Md. Nazmul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include <iomanip>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
#define lowest_int -2147483647
int main()
{
int test, n,p,x;
int petrol[200040];
sc("%d",&test);
int cs=1;
while(test--)
{
sc("%d",&n);
for(int i=1 ; i<=n ; i++)
{
sc("%d",&petrol[i]);
petrol[n+i] = petrol[i];
}
for(int i=1 ; i<=n ; i++)
{
sc("%d",&x);
petrol[i] -= x;
petrol[n+i] -= x;
}
petrol[0] =0;
for(int i=1 ; i<=2*n ; i++)
{
petrol[i] += petrol[i-1];
}
int s=0, mi=1,cnt=0;
for(int i=0 ; i<=2*n ; i++)
{
if(petrol[i]>=mi)
{
if(++cnt>n)
break;
}
else
{
mi = petrol[i];
s= i;
cnt=1 ;
if(i>=n)
break;
}
}
if(cnt>n)
pf("Case %d: Possible from station %d\n",cs++,s+1);
else
pf("Case %d: Not possible\n",cs++);
}
}
No comments:
Post a Comment