QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203026#2481. PickpocketsRd_rainydays#WA 1ms3864kbC++141.8kb2023-10-06 14:47:262023-10-06 14:47:27

Judging History

你现在查看的是最新测评结果

  • [2023-10-06 14:47:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3864kb
  • [2023-10-06 14:47:26]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<set>
#define N 200005
#define M 20
using namespace std;
int n,m;
int a[N];
struct zero{
  int len,val;
  friend bool operator<(zero a,zero b){return a.len>b.len;}
}lib[M];
priority_queue<int,vector<int>, greater<int> > q;
int siz=0;
int upper=0;
multiset<int> st;
int aux[M];
int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++){scanf("%d",a+i);upper=max(upper,a[i]);}
  a[n+1]=0;
  for(int u=1;u<=max(m,upper);u++){
    int las=0;
    for(int i=1;i<=n+1;i++){
      if(a[i]<u){
        int nwlen=i-1-las;
        if(siz==m){
         if(q.top()<nwlen){
          q.pop();q.push(nwlen);
         }
        }
        else {
          siz++;
          q.push(nwlen);
        }
        las=i;
      }
    }
  }
  for(int i=1;i<=siz;i++){aux[i]=q.top();q.pop();}
  for(int i=1;i<=m;i++)scanf("%d%d",&lib[i].len,&lib[i].val);
  sort(lib+1,lib+m+1);
  int ans=0;
  int flag=0;
  // printf("%d\n",siz);
  // for(int i=1;i<=siz;i++)cout<<aux[i]<<endl;
  for(int i=0;i<(1<<m);i++){
    st.clear();
    for(int r=1;r<=siz;r++)st.insert(aux[r]);
    flag=1;
    // cout<<"solve:"<<i<<endl;
    for(int r=1;r<=m;r++){
      if(((1<<(r-1))&i)==0)continue;
      // cout<<"now:"<<r<<" "<<lib[r].len<<" "<<lib[r].val<<endl;
      auto it=st.lower_bound(lib[r].len);
      if(it==st.end()){flag=false;break;}
      else {
        int las=*it-lib[r].len;
        st.erase(it);
        if(las>0)st.insert(las);
      }
    }
    if(!flag)continue; 
    // cout<<"OK\n";
    int sum=0;
    for(int r=1;r<=m;r++){
      if(((1<<(r-1))&i)==0)continue;
      sum+=lib[r].val;
    }
    ans=max(ans,sum);
  }
  printf("%d\n",ans);

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

input:

2 2
1 2
1 5
2 5

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

2 2
1 2
2 5
1 5

output:

10

result:

ok single line: '10'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

3 4
2 1 2
3 2
1 1
1 2
1 3

output:

7

result:

ok single line: '7'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

1 5
2
1 2
1 5
1 3
1 5
1 3

output:

10

result:

ok single line: '10'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

1 5
1
1 2
1 1
1 2
1 5
1 2

output:

5

result:

ok single line: '5'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

1 7
0
1 5
1 5
1 5
1 2
1 5
1 3
1 6

output:

0

result:

ok single line: '0'

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3852kb

input:

3 6
2 1 1
2 1
3 5
2 3
3 3
2 4
3 3

output:

5

result:

wrong answer 1st lines differ - expected: '0', found: '5'