【NOIP】选择客栈

Loi_cgold的详细解释

#include
#include
#include
using namespace std;
const int maxn=200000;
int tot[maxn],sum[maxn],h[maxn];
int n,k,p;//分别表示客栈的个数,色调的数目和能接受的最低消费的最高值
int ans,now;
int main()
{
    memset(tot,0,sizeof(tot));
    memset(sum,0,sizeof(sum));
    memset(h,0,sizeof(h));
    int a,b;
    scanf("%d%d%d",&n,&k,&p);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a,&b);
        if(b<=p) now=i;
        if(now>=h[a])
        {
            sum[a]=tot[a];
        }
        tot[a]++;ans+=sum[a];h[a]=i;
    }
    printf("%d\n",ans);
    return 0;
}

你可能感兴趣的:(贪心,模拟)