RT,这是我的40pts代码
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int tp[805];
int mp[805];
int now[805];
bool cmp(int x,int y){
return x>y;
}
int cnt=0,cnt1=0;
priority_queue<int> h;
namespace IO{
const int Buffsize=1<<23;
char c[Buffsize],*ch=c;
void INIT(){fread(c,1,Buffsize,stdin);}
int x,l;
int read(){
x=0,l=1;
while(!isdigit(*ch)) {if ((*ch)=='-') l=-1; ch++;}
while(isdigit(*ch)) x=x*10+(*ch^48),ch++;
return x*l;
}
}
using namespace IO;
int main(){
h.push(0);
INIT();
n=read();m=read();k=read();
for(int k1=1;k1<=n;k1++){
for(int i=1;i<=m;i++){
mp[i]=read();
}
sort(mp+1,mp+1+m,cmp);
cnt1=0;
cnt=0;
while(!h.empty()){
tp[++cnt]=h.top();
h.pop();
}
for(int i=1;i<=m;i++){
for(int j=cnt;j>=1;j--){
if(cnt1<k){
h.push(mp[i]+tp[j]);
cnt1++;
}else if(h.top()<=mp[i]+tp[j]) break;
else{
h.pop();
h.push(mp[i]+tp[j]);
}
}
}
}
cnt=0;
while(!h.empty()){
tp[++cnt]=h.top();
h.pop();
}
for(int i=k;i>=1;i--) printf("%d ",tp[i]);
return 0;
}
这是我的AC代码
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int tp[805];
int mp[805];
int cnt=0,cnt1=0;
priority_queue<int> h;
bool cmp(int x,int y){
return x>y;
}
namespace IO{
const int Buffsize=1<<23;
char c[Buffsize],*ch=c;
void INIT(){fread(c,1,Buffsize,stdin);}
int x,l;
int read(){
x=0,l=1;
while(!isdigit(*ch)) {if ((*ch)=='-') l=-1; ch++;}
while(isdigit(*ch)) x=x*10+(*ch^48),ch++;
return x*l;
}
}
using namespace IO;
int main(){
h.push(0);
INIT();
n=read();m=read();k=read();
for(int k1=1;k1<=n;k1++){
for(int i=1;i<=m;i++){
mp[i]=read();
}
sort(mp+1,mp+1+m);
cnt1=cnt=0;
while(!h.empty()){
tp[++cnt]=h.top();
h.pop();
}
for(int i=1;i<=m;i++){
for(int j=cnt;j>=1;j--){
if(cnt1<k){
h.push(mp[i]+tp[j]);
cnt1++;
}else if(h.top()<=mp[i]+tp[j]) break;
else{
h.pop();
h.push(mp[i]+tp[j]);
}
}
}
}
cnt=0;
while(!h.empty()){
tp[++cnt]=h.top();
h.pop();
}
for(int i=k;i>=1;i--) printf("%d ",tp[i]);
return 0;
}
真的有区别吗? 求助各位大佬