跳到正文

题解

题解:P12249 [科大国创杯初中组 2025] 果汁

pengyirui约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年4月20日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 2 分钟
题目
P12249

版本

  1. v1当前

思路

一看题目-包贪心的! 策略(因为单调不降):

  1. 如果下一个杯子可以装:装;
  2. 如果当前杯子可以装:装;
  3. 都不行:真好喝……

代码

真水呀!但是我为什么交了6次

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,T,v[999999],a[999999],ans;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>T;
    while(T--)
        {
            ans=0;
            cin>>n>>m;
            for(int i=1;i<=m;i++)cin>>v[i];
            for(int i=1;i<=n;i++)cin>>a[i];
            for(int i=1;i<=n;i++)
                {
                    if(v[a[i]+1]>0)v[a[i]+1]--;
                    else if(v[a[i]]>0)v[a[i]]--;
                    else ans++;
                }
            cout<<ans<<endl;
        }
	return 0;
}

完结撒花!!!

原文