Advertisement
a53

Minioni

a53
Dec 27th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4. ifstream f("minioni.in");
  5. ofstream g("minioni.out");
  6. const int MM = 101;
  7. const int KK = 505;
  8. int t[MM];
  9. long long dp[MM][KK];
  10.  
  11. inline long long suma(int n)
  12. {
  13. return (long long)n * (n + 1) / 2;
  14. }
  15.  
  16. inline long long rezolva_cladire(int n, int k)
  17. {
  18. int p = k + 1;
  19. int mp = n/p;
  20. int bp = (n+p-1)/p;
  21. int nmaj = n%p;
  22. int nmic = p-nmaj;
  23. return nmic * suma(mp) + nmaj*suma(bp);
  24. }
  25.  
  26. int main()
  27. {
  28. int N, M, K;
  29. f>>N>>M>>K;
  30. while (N--)
  31. {
  32. int cladire;
  33. f>>cladire;
  34. ++t[cladire];
  35. }
  36. for (int m=1;m<=M;++m)
  37. for (int k=0;k<=K;++k) {
  38. dp[m][k] =rezolva_cladire(t[m],0) + dp[m-1][k];
  39. for (int i=1;i<=k;++i)
  40. dp[m][k] = min(dp[m][k],rezolva_cladire(t[m],i) + dp[m-1][k-i]);
  41. }
  42. g<<dp[M][K];
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement