luogu1020 导弹拦截

来源:互联网 发布:线程优化 编辑:程序博客网 时间:2024/05/20 09:44
#include <algorithm>#include <iostream>#include <cstring>#include <cstdio>using namespace std;int a[100005], n, dp[100005], cnt;bool cmp1(int x, int y){    return x>=y;}int main(){    while(scanf("%d", &a[++n])!=EOF)    ;    n--;    dp[0] = 0x3f3f3f3f;    for(int i=1; i<=n; i++){        if(a[i]<=dp[cnt])   dp[++cnt] = a[i];        else                *lower_bound(dp+1, dp+1+cnt, a[i], cmp1) = a[i];    }    cout<<cnt<<endl;    memset(dp, 0, sizeof(dp));    cnt = 0;    for(int i=1; i<=n; i++){        if(a[i]>dp[cnt])    dp[++cnt] = a[i];        else                *upper_bound(dp+1, dp+1+cnt, a[i]) = a[i];    }    cout<<cnt;    return 0;}
原创粉丝点击