XYLX 10.19 集卡片

XYLX 10.19 集卡片


题目描述


boboo小时候很喜欢收集卡片,他经常要去商店购买新到的卡片。
商店出售的卡片有N张,是连续的,并且都连在一起成为一个长串,商店阿姨告诉boboo只能购买连续的一段,这一串卡片共有M种,每种卡片都有一个价格,boboo拿的钱数为V,他想花最少的钱来集齐所有种类的卡片,你能帮帮他吗?


输入输出


输入文件

第1行 三个正整数 N,M,V
第2行共M个正整数,第i个数Ti表示第i种卡片的价格
第3行 N个正整数,表示卡片序列。


输出文件

1行 1个整数ans,表示boboo剩余的钱数,若不能集齐,输出’NO ans’,不含引号。


样例


样例输入

5 2 20
10 5
1 1 2 2 1

样例输出

5


注释


【样例解释】

购买2-3 或者 4-5 都可,花费15,剩余钱数20-15=5.


【数据范围】

对于100%的数据 N<=1000000 ,M<=2000 ,Ti<=2000 , V<=10^9
对于30% 的数据 N<=2000


分析

该题直接从前向后扫即可,同时记录最小值,然后判断是否足够。
扫的同时如果队首元素后面出现过直接出队,因为在前面没有任何用途。


代码如下

program card;
var n,m,v,i:longint;
    price:array[1..2000] of longint;
    minn,now,x,kind:int64;
    can:array[1..2000] of longint;
    head,rear:longint;
    queue:array[1..1000000] of longint;
function min(a,b:int64):int64;
begin
 if a>b then exit(b);
 exit(a);
end;

begin
 readln(n,m,v);
 for i:=1 to m do
  begin
   read(price[i]);
   can[i]:=0;
  end;
 minn:=maxlongint; now:=0;
 head:=1;
 rear:=0;
 for i:=1 to n do
  begin
   read(x);
   inc(rear);
   queue[rear]:=x;
   if can[x]=0
    then kind:=kind+1;
   can[x]:=can[x]+1;
   now:=now+price[x];
   while can[queue[head]]>1  do
    begin
     now:=now-price[queue[head]];
     can[queue[head]]:=can[queue[head]]-1;
     head:=head+1;
    end;
   if kind=m
    then minn:=min(minn,now);
  end;
 if (minn>v) or (kind<m) then write('NO ans')
                         else write(v-minn);
end.

EVERYTHING HAS CHANGED

All I knew this morning when I woke Is I know something now, know
something now I didn’t before And all I’ve seen since 18 hours ago Is
green eyes and freckles and your smile in the back of my mind making
me feel like I just want to know you better,know you better,know you
better now I just want to know you better,know you better,know you
better now I just want to know you better,know you better,know you
better now I just want to know you,know you,know you Cause all I know
is we said hello And your eyes look like coming home All I know is a
simple name, everything has changed All I know is you held the door
You’ll be mine and I’ll be yours All I know since yesterday is
everything has changed And all my walls stood tall,painted blue I’ll
take ‘em down, take ‘em down and open up the door for you And all I
feel in my stomach is butterflies the beautiful kind Makin’ up for
lost time, takin’ flight making me feel like I just want to know you
better,know you better,know you better now I just want to know you
better,know you better,know you better now I just want to know you
better,know you better,know you better now I just want to know
you,know you,know you Cause all I know is we said hello And your eyes
look like coming home All I know is a simple name, everything has
changed All I know is you held the door You’ll be mine and I’ll be
yours All I know since yesterday is everything has changed Come back
and tell me why I’m feeling like I’ve missed you all this time And
meet me these tonight and let me know that it’s not all in my mind I
just want to know you better,know you better,know you better now I
just want to know you,know you,know you Cause all I know is we said
hello And your eyes look like coming home All I know it’s a simple
name, everything has changed All I know is we held the door You’ll be
mine and I’ll be yours All I know since yesterday is everything has
changed All I know is we said hello So dust off your highest hopes All
I know is pouring rain And everything has changed All I know is a new
found grace All my days I’ll know your face All I know since yesterday
is everything has changed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值