社区讨论

求条,悬关,急急急

P2949[USACO09OPEN] Work Scheduling G参与者 2已保存回复 6

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
6 条
当前快照
1 份
快照标识符
@mi4re8kx
此快照首次捕获于
2025/11/18 23:59
3 个月前
此快照最后确认于
2025/11/20 04:04
3 个月前
查看原帖
CPP
#include<bits/stdc++.h>
#define int long long
struct node{
    int t,m;
}w[1000010];
int n,ans;
priority_queue<int,vector<int>,greater<int> > que;
bool cmp(node a,node b){
    return a.t<b.t;
}
signed main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d%d",&w[i].t,&w[i].m);
    }
    sort(w+1,w+n+1,cmp);
    for(int i=1;i<=n;++i){
        if(w[i].t<=que.size()){
            if(w[i].m>que.top()){
                ans-=que.top();
                que.pop();
                que.push(w[i].m);
                ans+=w[i].m;
            }
        }else{
            q.push(w[i].m);
            ans+=w[i].m;
        }
    }
    printf("%lld",ans);
    return 0;
}
神秘 CE\text{{CE}}
CPP
/tmp/compiler_1t7yevxe/src:7:1: 错误:‘priority_queue’不是一个类型名
    7 | priority_queue<int,vector<int>,greater<int> > que;
      | ^~~~~~~~~~~~~~
/tmp/compiler_1t7yevxe/src: 在函数‘int main()’中:
/tmp/compiler_1t7yevxe/src:12:13: 警告:格式 ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
   12 |     scanf("%d",&n);
      |            ~^  ~~
      |             |  |
      |             |  long long int*
      |             int*
      |            %lld
/tmp/compiler_1t7yevxe/src:14:17: 警告:格式 ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
   14 |         scanf("%d%d",&w[i].t,&w[i].m);
      |                ~^    ~~~~~~~
      |                 |    |
      |                 int* long long int*
      |                %lld
/tmp/compiler_1t7yevxe/src:14:19: 警告:格式 ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘long long int*’ [-Wformat=]
   14 |         scanf("%d%d",&w[i].t,&w[i].m);
      |                  ~^          ~~~~~~~
      |                   |          |
      |                   int*       long long int*
      |                  %lld
/tmp/compiler_1t7yevxe/src:16:5: 错误:‘sort’ was not declared in this scope; did you mean ‘std::sort’?
   16 |     sort(w+1,w+n+1,cmp);
      |     ^~~~
      |     std::sort
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/algorithm:62,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:65,
                 from /tmp/compiler_1t7yevxe/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_algo.h:4887:5: 附注:‘std::sort’ declared here
 4887 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/tmp/compiler_1t7yevxe/src:18:20: 错误:‘que’在此作用域中尚未声明
   18 |         if(w[i].t<=que.size()){
      |                    ^~~
/tmp/compiler_1t7yevxe/src:26:13: 错误:‘q’在此作用域中尚未声明
   26 |             q.push(w[i].m);
      |             ^

回复

6 条回复,欢迎继续交流。

正在加载回复...