Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: wtfalex2
- LANG: C++14
- PROB: castle
- //9cz2b944
- */
- #define _CRT_SECURE_NO_WARNINGS
- #pragma comment(linker, "/STACK:256000000")
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <vector>
- #include <ctime>
- #include <map>
- #include <set>
- #include <string>
- #include <queue>
- #include <deque>
- #include <cassert>
- #include <cstdlib>
- #include <bitset>
- #include <algorithm>
- #include <string>
- #include <list>
- #include <fstream>
- #include <cstring>
- #include <climits>
- #include <stack>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef vector<int> vi;
- typedef pair<string, int> psi;
- typedef vector<string> vs;
- typedef pair<ll, ll> pll;
- typedef vector<ll> vll;
- typedef vector<char> vc;
- typedef vector<pii> vpii;
- typedef vector<pair<ll, ll> > vpll;
- typedef long double ld;
- #define forn(i, n) for (int i = 0; i < (int)n; i++)
- #define for1(i, n) for (int i = 1; i <= (int)n; i++)
- #define forq(i, s, t) for (int i = s; i <= t; i++)
- #define ford(i, s, t) for (int i = s; i >= t; i--)
- #define mk make_pair
- #define inb push_back
- #define outb pop_back
- #define all(v) v.begin(), v.end()
- #define X first
- #define Y second
- #define TIME clock() * 1.0 / CLOCKS_PER_SEC
- #define sqr(x) (x) * (x)
- #define y1 amdknkgsdaasdwapgnpikn
- //
- #define mp make_pair
- #define pb push_back
- #define XX first
- #define YY second
- //
- const ld EPS = 1e-9;
- const ld pi = acos(-1.0);
- const int MAXN = (int)1e5 + 7;
- const ll INF = 2e9 + 7;
- const ll LINF = (ll)7e18;
- const ll MOD = (ll)1e9 + 7;
- const int CHASH = (ll)239017;
- const ld DINF = (ld)1000000000000000.0;
- void mkfile();
- int solve();
- int main()
- {
- #define TASK "tallbarn"
- #ifdef _DEBUG
- mkfile();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- freopen("test.txt", "w", stderr);
- ld tstart = TIME;
- srand(2299);
- #else
- freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
- //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
- srand(2299);
- #endif
- solve();
- #ifdef _DEBUG
- ld tend = TIME;
- cerr << tend - tstart << " s.\n";
- #endif
- return 0;
- }
- void mkfile()
- {
- freopen("input.txt", "a+", stdout);
- srand(time(0));
- return;
- }
- bool equal(double a, double b)
- {
- return abs(a - b) < EPS;
- }
- struct Point
- {// vector
- double x, y;
- int id;
- Point() {};
- Point(double x, double y) : x(x), y(y) {};
- //point mul by double
- Point operator*(double d) { return Point(x * d, y * d); }
- //point + vector
- Point operator+(Point p) { return Point(x + p.x, y + p.y); }
- Point operator-(Point p) { return Point(x - p.x, y - p.y); }
- //dotProduct
- double operator%(Point p) { return x * p.x + y * p.y; }
- //crossProduct
- double operator*(Point p) { return x * p.y - y * p.x; }
- // rasstoyanie
- bool operator== (Point p) { return equal(x, p.x) && equal(y, p.y); }
- // equal
- double distancetoPoint(Point p)
- {
- return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
- }
- // vector length \ distance from zero to Point
- double len() { return sqrt(x * x + y * y); }
- double angle(Point p) { return atan2((*this) * p, (*this) % p); }
- // turnByAngle
- Point turnByAngle(double a) {
- double cosa = cos(a); double sina = sin(a);
- return Point(x * cosa - y * sina, x * sina + y * cosa);
- }
- Point getNormVec()
- {
- return Point(x / (*this).len(), y / (*this).len());
- }
- };
- Point makeV(Point a, Point b) { return a - b; }
- const Point NULLP = Point(1e9 + 7, 1e9 + 9);
- const Point EQ = Point(13888, 888283);
- const Point INFPTS = Point(1e9 + 17, 1e9 + 19);
- struct Line
- {
- double a, b, c;
- Point q, w;
- Line() {};
- Line(double a, double b, double c) : a(a), b(b), c(c) {};
- Line(Point p, Point t) {
- a = t.y - p.y; // -n.y
- b = p.x - t.x; // n.x
- c = -a * p.x - b * p.y;
- q = p;
- w = t;
- }
- bool eq_null(Line l)
- {
- return (l.a == a) && (l.b == b) && (l.c == c);
- }
- // oriented!!!
- double distanceFromPoint(Point p) {
- return (a * p.x + b * p.y + c) / Point(a, b).len();
- }
- bool operator||(Line l) {
- return equal(Point(a, b) * Point(l.a, l.b), 0);
- }
- bool ifeq(Line l)
- {
- Point v1 = makeV(q, w);
- Point v2 = makeV(l.q, l.w);
- Point v11 = makeV(l.w, w);
- Point v22 = makeV(q, l.q);
- if (v1 * v2 == 0 && v11 * v22 == 0)
- return 1;
- return 0;
- }
- Point operator^(Line l)
- {
- //if ((*this).ifeq(l))
- //return EQ;
- double d = Point(a, b) * Point(l.a, l.b);
- if (equal(d, 0))
- return NULLP;
- double x = (b * l.c - l.b * c) / d;
- double y = (c * l.a - l.c * a) / d;
- return Point(x, y);
- }
- };
- istream& operator>> (istream &input_stream, Point &a) {
- input_stream >> a.x >> a.y;
- return input_stream;
- }
- istream& operator>> (istream &input_stream, Line &a)
- {
- input_stream >> a.a >> a.b >> a.c;
- return input_stream;
- }
- ostream& operator<<(ostream &output_stream, Point &a) {
- output_stream.precision(15);
- output_stream << fixed << a.x << " " << a.y;
- return output_stream;
- }
- ostream& operator<<(ostream &output_stream, Line &a) {
- output_stream.precision(15);
- output_stream << fixed << a.a << " " << a.b << " " << a.c;
- return output_stream;
- }
- int n;
- ll a[MAXN], k, sum, fr;
- ll cnt[MAXN];
- set < pair <double, int> > q;
- int solve()
- {
- scanf("%d %lld", &n, &k);
- forn(i, n)
- {
- scanf("%lld", &a[i]);
- sum += a[i];
- }
- fr = k;
- forn(i, n)
- {
- cnt[i] = (ll)((double)a[i] / (double)sum * (double)k);
- fr -= cnt[i];
- q.insert(mk((double)a[i] * (1.0 / (double)(cnt[i]) - 1.0 / (double)(cnt[i] + 1)), i));
- }
- forn(Q, fr)
- {
- pair <double, int> cur = (*q.rbegin());
- ++cnt[cur.Y];
- q.erase((*q.rbegin()));
- int i = cur.Y;
- q.insert(mk((double)a[i] * (1.0 / (double)(cnt[i]) - 1.0 / (double)(cnt[i] + 1)), i));
- }
- double ans = 0;
- forn(i, n)
- ans += (double)a[i] / (double)cnt[i];
- cout << (ll)(round(ans));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement