Antithese

· · 题解

注意到我们只保留所有将 a_i 从 0 变为 1 的操作是最优的,否则,和绝对会减少。

所以保留这些即可。

#include<bits/stdc++.h>
using namespace std;

const int N=1e6+5;
int n,m,a[N];

signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        char c;cin>>c;
        a[i]=c-'0';
    }
    for(int i=1,x;i<=m;i++){
        cin>>x;
        if(a[x]==0) a[x]=1;
    }
    int res=0;
    for(int i=1;i<=n;i++) res+=a[i];
    cout<<res;
    return 0;
}