Submission #1030801

# Submission time Handle Problem Language Result Execution time Memory
1030801 2024-07-22T10:22:14 Z Otalp Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
235 ms 600 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define pb push_back


pii a[200100];

bool cmp(pii a, pii b){
    return a.ss < b.ss;
}

 

void solve(){
    int n, k;
    cin>>n>>k;
    int dmx = 0;
    for(int i=1; i<=n; i++){
        cin>>a[i].ff>>a[i].ss;
        if(a[i].ss == -1){
            a[i].ss = 1e9;
        }
    }
    sort(a + 1, a + 1 + n, cmp);
    //for(int i=1; i<=n; i++) cout<<a[i].ff<<' '<<a[i].ss<<'\n';
    ld ans = 1e18;
    for(ld D=1; D<=k+1; D++){
        vector<int> d;
        ld res = 0;
        int m = k - D+1;
        int ok = 1;
        for(int i=1; i<=D-1; i++){
            d.pb(i);
            res += 1.0 * a[i].ss / i;
        }
        multiset<pii> dd, wl;
        for(int i=D; i<=n; i++){
            dd.insert({a[i].ff, i});
            if(dd.size() > m){
                wl.insert(*--(dd.end()));
                dd.erase(--(dd.end()));
            }
        }
        for(pii x: dd){
            res += x.ff / D;
        }
        //cout<<"________________\n";
        //cout<<D<<'\n';
        ans = min(ans, res);
        for(int i=D; i<=n; i++){
            pair<ld, int> mn{1e18, -1};
            res += a[i].ss / D;
            d.pb(i);
            int mx;
            if(dd.find({a[i].ff, i}) != dd.end()){
                dd.erase(dd.find({a[i].ff, i}));
                res -= a[i].ff / D;
                if(wl.size() == 0){
                    mx = 0;
                }
                else{
                    dd.insert(*wl.begin());
                    res += (*wl.begin()).ff / D;
                    wl.erase(wl.begin());
                    mx = (*dd.rbegin()).ff;
                }
            }
            else{
                mx = (dd.size() ?(*dd.rbegin()).ff :0);
            }
            ld g = 0;
            for(int i=d.size() - 1; i>=0; i--){
                int j = d[i];
                if(mx == 0){
                    mn = min(mn, {-a[j].ss * 1.0 / (i + 1) + g + a[j].ff / D, j});
                }
                else{
                    if(a[j].ff < mx){
                        mn = min(mn, {-a[j].ss * 1.0 / (i + 1) + g - mx / D + a[j].ff / D, j});
                    }
                    else{
                        mn = min(mn, {-a[j].ss * 1.0 / (i + 1) + g, j});
                    }
                }
                if(i > 0) g += -a[j].ss * 1.0 / (i + 1) + a[j].ss * 1.0 / i;
            }
            res += mn.ff;
            dd.insert({a[mn.ss].ff, mn.ss});
            if(dd.size() > m){
                wl.insert(*--(dd.end()));
                dd.erase(--(dd.end()));
            }
            ans = min(ans, res);
            vector<int> dq;
            for(int x: d){
                if(x != mn.ss) dq.pb(x);
            }
            d =dq;
            //cout<<res<<'\n';
            //for(pii x: dd) cout<<x.ff<<' '<<x.ss<<'\n';
                
        }
    }
    cout<<fixed<<setprecision(6)<<ans<<'\n';
}
 
 
signed main(){
    solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:45:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   45 |             if(dd.size() > m){
      |                ~~~~~~~~~~^~~
Main.cpp:95:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   95 |             if(dd.size() > m){
      |                ~~~~~~~~~~^~~
Main.cpp:37:13: warning: unused variable 'ok' [-Wunused-variable]
   37 |         int ok = 1;
      |             ^~
Main.cpp:23:9: warning: unused variable 'dmx' [-Wunused-variable]
   23 |     int dmx = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 12 ms 512 KB Output is correct
6 Correct 40 ms 504 KB Output is correct
7 Correct 101 ms 348 KB Output is correct
8 Correct 170 ms 348 KB Output is correct
9 Correct 215 ms 348 KB Output is correct
10 Correct 138 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 12 ms 512 KB Output is correct
6 Correct 40 ms 504 KB Output is correct
7 Correct 101 ms 348 KB Output is correct
8 Correct 170 ms 348 KB Output is correct
9 Correct 215 ms 348 KB Output is correct
10 Correct 138 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 60 ms 500 KB Output is correct
13 Correct 57 ms 348 KB Output is correct
14 Correct 56 ms 344 KB Output is correct
15 Correct 217 ms 344 KB Output is correct
16 Correct 179 ms 468 KB Output is correct
17 Correct 169 ms 600 KB Output is correct
18 Correct 185 ms 348 KB Output is correct
19 Correct 182 ms 348 KB Output is correct
20 Correct 206 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 444 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 444 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 3 ms 348 KB Output is correct
47 Correct 3 ms 348 KB Output is correct
48 Correct 3 ms 348 KB Output is correct
49 Correct 4 ms 440 KB Output is correct
50 Correct 3 ms 348 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
52 Correct 4 ms 348 KB Output is correct
53 Correct 3 ms 348 KB Output is correct
54 Correct 3 ms 440 KB Output is correct
55 Correct 3 ms 344 KB Output is correct
56 Correct 3 ms 348 KB Output is correct
57 Correct 3 ms 348 KB Output is correct
58 Correct 3 ms 348 KB Output is correct
59 Correct 5 ms 348 KB Output is correct
60 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 206 ms 464 KB Output is correct
2 Correct 210 ms 476 KB Output is correct
3 Correct 210 ms 348 KB Output is correct
4 Correct 201 ms 468 KB Output is correct
5 Correct 216 ms 468 KB Output is correct
6 Correct 184 ms 348 KB Output is correct
7 Correct 214 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 12 ms 512 KB Output is correct
6 Correct 40 ms 504 KB Output is correct
7 Correct 101 ms 348 KB Output is correct
8 Correct 170 ms 348 KB Output is correct
9 Correct 215 ms 348 KB Output is correct
10 Correct 138 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 60 ms 500 KB Output is correct
13 Correct 57 ms 348 KB Output is correct
14 Correct 56 ms 344 KB Output is correct
15 Correct 217 ms 344 KB Output is correct
16 Correct 179 ms 468 KB Output is correct
17 Correct 169 ms 600 KB Output is correct
18 Correct 185 ms 348 KB Output is correct
19 Correct 182 ms 348 KB Output is correct
20 Correct 206 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 444 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 460 KB Output is correct
63 Correct 2 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 2 ms 348 KB Output is correct
66 Correct 3 ms 348 KB Output is correct
67 Correct 3 ms 348 KB Output is correct
68 Correct 3 ms 348 KB Output is correct
69 Correct 4 ms 440 KB Output is correct
70 Correct 3 ms 348 KB Output is correct
71 Correct 3 ms 348 KB Output is correct
72 Correct 4 ms 348 KB Output is correct
73 Correct 3 ms 348 KB Output is correct
74 Correct 3 ms 440 KB Output is correct
75 Correct 3 ms 344 KB Output is correct
76 Correct 3 ms 348 KB Output is correct
77 Correct 3 ms 348 KB Output is correct
78 Correct 3 ms 348 KB Output is correct
79 Correct 5 ms 348 KB Output is correct
80 Correct 3 ms 348 KB Output is correct
81 Correct 206 ms 464 KB Output is correct
82 Correct 210 ms 476 KB Output is correct
83 Correct 210 ms 348 KB Output is correct
84 Correct 201 ms 468 KB Output is correct
85 Correct 216 ms 468 KB Output is correct
86 Correct 184 ms 348 KB Output is correct
87 Correct 214 ms 348 KB Output is correct
88 Correct 12 ms 348 KB Output is correct
89 Correct 15 ms 348 KB Output is correct
90 Correct 44 ms 348 KB Output is correct
91 Correct 42 ms 348 KB Output is correct
92 Correct 128 ms 348 KB Output is correct
93 Correct 112 ms 348 KB Output is correct
94 Correct 174 ms 348 KB Output is correct
95 Correct 180 ms 492 KB Output is correct
96 Correct 225 ms 348 KB Output is correct
97 Correct 235 ms 348 KB Output is correct
98 Correct 144 ms 472 KB Output is correct
99 Correct 143 ms 348 KB Output is correct
100 Correct 182 ms 348 KB Output is correct
101 Correct 192 ms 348 KB Output is correct
102 Correct 184 ms 480 KB Output is correct
103 Correct 200 ms 348 KB Output is correct
104 Correct 185 ms 480 KB Output is correct
105 Correct 141 ms 468 KB Output is correct