Submission #554418

#TimeUsernameProblemLanguageResultExecution timeMemory
554418Ronin13Let's Win the Election (JOI22_ho_t3)C++14
10 / 100
399 ms2328 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define ull unsigned ll #define pb push_back #define epb emplace_back using namespace std; const double inf = 1e9 + 1; int main(){ int n; cin >> n; int k; cin >> k; pair<double, double> a[n + 1]; for(int i = 1; i <= n; i++){ cin >> a[i].s >> a[i].f; if(a[i].f == -1) a[i].f = inf; } sort(a + 1, a + 1 + n); for(int i = 1; i <= n; i++){ //cout << a[i].f << ' ' << a[i].s << "\n"; } double ans = inf; for(int x = 0; x <= n; x++){ double dp[n + 1][n + 1]; for(int i = 0; i <= n; i++){ for(int j = 0; j <= n; j++) dp[i][j] = inf; } dp[0][0] = 0; for(int i = 1; i <= n; i++){ for(int j = 0; j <= n; j++){ if(j > 0)dp[i][j] =min(dp[i][j], dp[i - 1][j - 1] + a[i].f / j); dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i].s / (x + 1)); } } double cursum = 0; multiset <pair<double, int> > st; for(int i = 1; i <= n; i++){ cursum += a[i].s; st.insert({a[i].s, i}); } while(st.size() > k) { cursum -= st.rbegin() -> f; st.erase(st.find(*st.rbegin())); } for(int i = 1; i <= n; i++){ double cur = dp[i - 1][x]; cur += cursum / (x + 1); if(ans > cur){ //cout << dp[i - 1][x] << "\n"; //cout << x << ' ' << i; //cout << "\n"; ans = cur; } multiset <pair<double, int> > :: iterator it = st.find({a[i].s, i}); if(it != st.end()){ cursum -= a[i].s; st.erase({a[i].s, i}); } if(st.size() > k - i && !st.empty()){ cursum -= st.rbegin() -> f; st.erase(st.find(*st.rbegin())); } } } cout << fixed << setprecision(3) << ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:45:25: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<double, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |         while(st.size() > k) {
      |               ~~~~~~~~~~^~~
Main.cpp:63:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<double, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |             if(st.size() > k - i && !st.empty()){
      |                ~~~~~~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...