-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtowers.cpp
41 lines (41 loc) · 908 Bytes
/
towers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# include <iostream>
# include <algorithm>
using namespace std;
int i,j,n,k,I,J,Inst,VV,maxx,minn,sol[10000],a[10000];
int main ()
{
cin>>n>>k;
for (i=1; i<=n; ++i)
cin>>a[i];
if (n==1)
{
cout<<"0 0\n";
return 0;
}
for (i=1; i<=k; ++i)
{
minn=a[1]; I=1; maxx=0;
for (j=1; j<=n; ++j)
{
if (a[j]<minn) minn=a[j], I=j;
if (a[j]>maxx) maxx=a[j], J=j;
}
if (minn<maxx)
{
--a[J]; ++a[I];
sol[++VV]=J; sol[++VV]=I;
}
minn=a[1]; maxx=0;
for (j=1; j<=n; ++j)
{
if (a[j]<minn) minn=a[j], I=j;
if (a[j]>maxx) maxx=a[j], J=j;
}
Inst=maxx-minn;
if (Inst==0) break;
}
cout<<Inst<<" "<<VV/2<<"\n";
for (i=1; i<=VV-1; i+=2)
cout<<sol[i]<<" "<<sol[i+1]<<"\n";
return 0;
}