#include<iostream>
#include<string>
using namespace std;
struct work
{
int time;
int number;
};
int setwork0(int m,int n,int a[],struct work w[])
{
int maxtime=0;
for(int i=1; i<=m; i++)
{
cout<<i<<"号设备处理作业"<<w[i].number<<endl;
a[i]=w[i].time;
if(maxtime<a[i])
maxtime=a[i];
}
return maxtime;
}
int setwork1(int m,int n,int a[],struct work w[])
{
int maxtime=0;
for(int i=1; i<=n; i++)
{
a[i]=w[i].time;
cout<<i<<"号设备处理作业"<<w[i].number<<endl;
}
int t=n+1;
while(t<=m)
{
int min0=n;
for(int i=1; i<=n; i++)
{
if(a[min0]>a[i])
{
min0=i;
}
}
a[min0]+=w[t].time;
cout<<min0<<"号设备处理作业"<<w[t].number<<endl;
t++;
}
for(int i=1; i<=n; i++)
{
if(maxtime<a[i])
maxtime=a[i];
}
return maxtime;
}
int main()
{
int n;
cout<<"共有n个设备:";
cin>>n;
int m;
cout<<"共有m个作业:";
cin>>m;
struct work w[m+1];
cout<<"输入处理时间:";
for(int i=1; i<=m; i++)
{
w[i].number=i;
cin>>w[i].time;
}
int a[n+12];
int maxtime=0;
if(m<=n)
maxtime=setwork0(m,n,a,w);
else
{
for(int i=1; i<=m; i++)
{
for(int j=i; j<=m; j++)
{
if(w[i].time<w[j].time)
{
struct work t=w[i];
w[i]=w[j];
w[j]=t;
}
}
}
for(int i=1; i<=m; i++)
{
cout<<w[i].number<<"号作业的处理时间:"<<w[i].time<<endl;
}
maxtime=setwork1(m,n,a,w);
}
cout<<"最长处理时间:"<<maxtime;
return 0;
}