CF A.Mishka and Contest【雙指針/模擬】
阿新 • • 發佈:2018-06-23
tdi pac long 消失 clu cin fix OS code
【鏈接】:CF/4892
【題意】:
一個人解決n個問題,這個問題的值比k小,
每次只能解決最左邊的或者最右邊的問題
解決了就消失了。問這個人能解決多少個問題。
【代碼】:
#include<bits/stdc++.h> #define PI acos(-1.0) #define pb push_back #define F first #define S second #define debug puts #define setp cout << fixed << setprecision(3) #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typedef long long ll; const int N=3e5+5; const int MOD=1e9+7; const ll INF=1e18+8; int n,k; int a[N]; int main() { FAST_IO while(cin>>n>>k) { int i=0; int cnt=0; for(int i=0;i<n;i++) { cin>>a[i]; } int l=0,r=n-1; while(1) { if( (a[l]>k && a[r]>k ) || i==n ) break; if(a[l]<=k) { l++; cnt++; } else if(a[r]<=k) { r--; cnt++; } i++; } cout<<cnt<<endl; } } /* 8 4 5 1 6 4 5 5 2 3 1 2 1 3 0 */
CF A.Mishka and Contest【雙指針/模擬】