out_of_theblue10

northcoders_strung.cpp

Apr 9th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <fstream>
  2. #define MAXM 110
  3. using namespace std;
  4. int diff,timp,i,j,x,n,m,proces[MAXM],minim,maxim;
  5. int main()
  6. {
  7.     ifstream fi("strung.in");
  8.     ofstream fo("strung.out");
  9.     fi>>m>>n;
  10.     proces[0]=int(2e9);
  11.     for(i=1;i<=n;i++)
  12.     {
  13.         fi>>x;
  14.         minim=0;
  15.         for(j=1;j<=m;j++) if(proces[j]<proces[minim]) minim=j;
  16.         timp+=proces[minim];
  17.         diff=proces[minim];
  18.         proces[minim]+=x;
  19.         for(j=1;j<=m;j++) proces[j]-=diff;
  20.     }
  21.     maxim=0;
  22.     for(j=1;j<=m;j++) if(maxim<proces[j]) maxim=proces[j]; //ce a mai ramas
  23.     fo<<timp+maxim<<"\n";
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment