Instantly share code, notes, and snippets.

# IKKO-Ohta/ABC032[C].cpp Last active Jul 16, 2017

 //------------------------------------------ // C++ templete //------------------------------------------ #include #define int long long using namespace std; //typedef //------------------------------------------ typedef pair PII; typedef vector VI; typedef vector VVI; typedef vector VS; typedef vector VP; //REPEAT //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) //container util //------------------------------------------ #define pb push_back #define paired make_pair #define ALL(a) (a).begin(),(a).end() #define PRINT(V) for (auto v : (V)) cout << v << " " #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) //constant //------------------------------------------ const int MOD = 1000000007; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; //math //------------------------------------------ int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;} int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;} int GCD(int a,int b){return b?GCD(b,a%b):a;} //debug //------------------------------------------ #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; template ostream& operator<<(ostream& s, const vector& v) { int len = v.size(); for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << "\t"; } return s; } template ostream& operator<<(ostream& s, const vector< vector >& vv) { int len = vv.size(); for (int i = 0; i < len; ++i) { s << vv[i] << endl; } return s; } //global variable //------------------------------------------ int N,K; VI vec; VI res; int cnt; bool flag = false; //main //------------------------------------------ signed main(){ cin >> N >> K; int t = 0; REP(i,N){ cin >> t; vec.pb(t); if(t == 0){ flag = true; } } if (flag){ cout << N << endl; exit(0); } if(K == 0){ cout << 0 << endl; exit(0); } int i = 0,j = 0; int x = 1, ans = 0; for(i = 0; i < N; i++){ x = x * vec[i]; if(x > K){ ans = max(ans,i-j); while(x > K){ x = x / vec[j]; j++; } } } if (x <= K) ans = max(ans,i-j); cout << ans << endl; }