Advertisement
K_Y_M_bl_C

Untitled

Jan 16th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.89 KB | None | 0 0
  1. /*
  2. ID: wtfalex2
  3. LANG: C++14
  4. PROB: castle
  5. //9cz2b944
  6. */
  7. #define _CRT_SECURE_NO_WARNINGS
  8. #pragma comment(linker, "/STACK:256000000")
  9.  
  10. #include <iostream>
  11. #include <cstdio>
  12. #include <cmath>
  13. #include <vector>
  14. #include <ctime>
  15. #include <map>
  16. #include <set>
  17. #include <string>
  18. #include <queue>
  19. #include <deque>
  20. #include <cassert>
  21. #include <cstdlib>
  22. #include <bitset>
  23. #include <algorithm>
  24. #include <string>
  25. #include <list>
  26. #include <fstream>
  27. #include <cstring>
  28. #include <climits>
  29. #include <stack>
  30. #include <unordered_map>
  31. #include <unordered_set>
  32.  
  33. using namespace std;
  34.  
  35. typedef unsigned long long ull;
  36. typedef long long ll;
  37. typedef pair<int, int> pii;
  38. typedef vector<int> vi;
  39. typedef pair<string, int> psi;
  40. typedef vector<string> vs;
  41. typedef pair<ll, ll> pll;
  42. typedef vector<ll> vll;
  43. typedef vector<char> vc;
  44. typedef vector<pii> vpii;
  45. typedef vector<pair<ll, ll> > vpll;
  46. typedef long double ld;
  47.  
  48. #define forn(i, n) for (int i = 0; i < (int)n; i++)
  49. #define for1(i, n) for (int i = 1; i <= (int)n; i++)
  50. #define forq(i, s, t) for (int i = s; i <= t; i++)
  51. #define ford(i, s, t) for (int i = s; i >= t; i--)
  52. #define mk make_pair
  53. #define inb push_back
  54. #define outb pop_back
  55. #define all(v) v.begin(), v.end()
  56. #define X first
  57. #define Y second
  58. #define TIME clock() * 1.0 / CLOCKS_PER_SEC
  59. #define sqr(x) (x) * (x)
  60. #define y1 amdknkgsdaasdwapgnpikn
  61. //
  62. #define mp make_pair
  63. #define pb push_back
  64. #define XX first
  65. #define YY second
  66. //
  67.  
  68. const ld EPS = 1e-9;
  69. const ld pi = acos(-1.0);
  70.  
  71. const int MAXN = (int)1e5 + 7;
  72. const ll INF = 2e9 + 7;
  73. const ll LINF = (ll)7e18;
  74. const ll MOD = (ll)1e9 + 7;
  75. const int CHASH = (ll)239017;
  76. const ld DINF = (ld)1000000000000000.0;
  77.  
  78. void mkfile();
  79. int solve();
  80.  
  81. int main()
  82. {
  83. #define TASK "tallbarn"
  84. #ifdef _DEBUG
  85.     mkfile();
  86.     freopen("input.txt", "r", stdin);
  87.     freopen("output.txt", "w", stdout);
  88.     freopen("test.txt", "w", stderr);
  89.     ld tstart = TIME;
  90.     srand(2299);
  91. #else
  92.     freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
  93.     //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
  94.     srand(2299);
  95. #endif
  96.     solve();
  97. #ifdef _DEBUG
  98.     ld tend = TIME;
  99.     cerr << tend - tstart << " s.\n";
  100. #endif
  101.     return 0;
  102. }
  103.  
  104. void mkfile()
  105. {
  106.     freopen("input.txt", "a+", stdout);
  107.     srand(time(0));
  108.     return;
  109. }
  110.  
  111. bool equal(double a, double b)
  112. {
  113.     return abs(a - b) < EPS;
  114. }
  115.  
  116. struct Point
  117. {// vector
  118.     double x, y;
  119.     int id;
  120.     Point() {};
  121.     Point(double x, double y) : x(x), y(y) {};
  122.     //point mul by double
  123.     Point operator*(double d) { return Point(x * d, y * d); }
  124.     //point + vector
  125.     Point operator+(Point p) { return Point(x + p.x, y + p.y); }
  126.     Point operator-(Point p) { return Point(x - p.x, y - p.y); }
  127.     //dotProduct
  128.     double operator%(Point p) { return x * p.x + y * p.y; }
  129.     //crossProduct
  130.     double operator*(Point p) { return x * p.y - y * p.x; }
  131.     // rasstoyanie
  132.     bool operator== (Point p) { return equal(x, p.x) && equal(y, p.y); }
  133.     // equal
  134.     double distancetoPoint(Point p)
  135.     {
  136.         return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
  137.     }
  138.     // vector length \ distance from zero to Point
  139.     double len() { return sqrt(x * x + y * y); }
  140.     double angle(Point p) { return atan2((*this) * p, (*this) % p); }
  141.     // turnByAngle
  142.     Point turnByAngle(double a) {
  143.         double cosa = cos(a); double sina = sin(a);
  144.         return Point(x * cosa - y * sina, x * sina + y * cosa);
  145.     }
  146.     Point getNormVec()
  147.     {
  148.         return Point(x / (*this).len(), y / (*this).len());
  149.     }
  150. };
  151.  
  152. Point makeV(Point a, Point b) { return a - b; }
  153. const Point NULLP = Point(1e9 + 7, 1e9 + 9);
  154. const Point EQ = Point(13888, 888283);
  155. const Point INFPTS = Point(1e9 + 17, 1e9 + 19);
  156.  
  157. struct Line
  158. {
  159.     double a, b, c;
  160.     Point q, w;
  161.     Line() {};
  162.     Line(double a, double b, double c) : a(a), b(b), c(c) {};
  163.     Line(Point p, Point t) {
  164.         a = t.y - p.y; // -n.y
  165.         b = p.x - t.x; // n.x
  166.         c = -a * p.x - b * p.y;
  167.         q = p;
  168.         w = t;
  169.     }
  170.  
  171.     bool eq_null(Line l)
  172.     {
  173.         return (l.a == a) && (l.b == b) && (l.c == c);
  174.     }
  175.  
  176.     // oriented!!!
  177.     double distanceFromPoint(Point p) {
  178.         return (a * p.x + b * p.y + c) / Point(a, b).len();
  179.     }
  180.  
  181.     bool operator||(Line l) {
  182.         return equal(Point(a, b) * Point(l.a, l.b), 0);
  183.     }
  184.  
  185.     bool ifeq(Line l)
  186.     {
  187.         Point v1 = makeV(q, w);
  188.         Point v2 = makeV(l.q, l.w);
  189.         Point v11 = makeV(l.w, w);
  190.         Point v22 = makeV(q, l.q);
  191.         if (v1 * v2 == 0 && v11 * v22 == 0)
  192.             return 1;
  193.         return 0;
  194.     }
  195.  
  196.     Point operator^(Line l)
  197.     {
  198.         //if ((*this).ifeq(l))
  199.         //return EQ;
  200.         double d = Point(a, b) * Point(l.a, l.b);
  201.         if (equal(d, 0))
  202.             return NULLP;
  203.         double x = (b * l.c - l.b * c) / d;
  204.         double y = (c * l.a - l.c * a) / d;
  205.         return Point(x, y);
  206.     }
  207. };
  208.  
  209. istream& operator>> (istream &input_stream, Point &a) {
  210.     input_stream >> a.x >> a.y;
  211.     return input_stream;
  212. }
  213.  
  214. istream& operator>> (istream &input_stream, Line &a)
  215. {
  216.     input_stream >> a.a >> a.b >> a.c;
  217.     return input_stream;
  218. }
  219.  
  220. ostream& operator<<(ostream &output_stream, Point &a) {
  221.     output_stream.precision(15);
  222.     output_stream << fixed << a.x << " " << a.y;
  223.     return output_stream;
  224. }
  225.  
  226. ostream& operator<<(ostream &output_stream, Line &a) {
  227.     output_stream.precision(15);
  228.     output_stream << fixed << a.a << " " << a.b << " " << a.c;
  229.     return output_stream;
  230. }
  231.  
  232. int n;
  233. ll a[MAXN], k, sum, fr;
  234. ll cnt[MAXN];
  235. set < pair <double, int> > q;
  236.  
  237. int solve()
  238. {
  239.     scanf("%d %lld", &n, &k);
  240.     forn(i, n)
  241.     {
  242.         scanf("%lld", &a[i]);
  243.         sum += a[i];
  244.     }
  245.     fr = k;
  246.     forn(i, n)
  247.     {
  248.         cnt[i] = (ll)((double)a[i] / (double)sum * (double)k);
  249.         fr -= cnt[i];
  250.         q.insert(mk((double)a[i] * (1.0 / (double)(cnt[i]) - 1.0 / (double)(cnt[i] + 1)), i));
  251.     }
  252.     forn(Q, fr)
  253.     {
  254.         pair <double, int> cur = (*q.rbegin());
  255.         ++cnt[cur.Y];
  256.         q.erase((*q.rbegin()));
  257.         int i = cur.Y;
  258.         q.insert(mk((double)a[i] * (1.0 / (double)(cnt[i]) - 1.0 / (double)(cnt[i] + 1)), i));
  259.     }
  260.     double ans = 0;
  261.     forn(i, n)
  262.         ans += (double)a[i] / (double)cnt[i];
  263.     cout << (ll)(round(ans));
  264.     return 0;
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement