f631.
同學會
--
林口高中練習題
| From: [42.73.59.35] |
發表日期
:
2023-08-25 16:07
想請問程式哪裡有錯誤
#include<stdio.h>
int main(){
int n,m;
while(scanf("%d %d",&n,&m)!=EOF){
int student[n],student_pay[n],meal[m];
int money=0,pay=0,max=0,max_flag=0;
for(int i=0;i<n;i++){
scanf("%d",&student[i]);
student_pay[i]=student[i];
money+=student[i];
if(student[max_flag]<student[i]){
max_flag=i;
}
}
for(int i=0;i<m;i++){
scanf("%d",&meal[i]);
pay+=meal[i];
}
max=max_flag;
if(money<pay){
printf("Oh My God\n");
}else{
for(int j=0;j<m;j++){
student_pay[max]-=meal[j];
for(int i=0;i<n;i++){
if(student_pay[max]<student_pay[i]){
max=i;
}
}
}
printf("%d %d\n",student[max_flag],student_pay[max]);
}
}
}