Submission #916895

#TimeUsernameProblemLanguageResultExecution timeMemory
916895ace5Let's Win the Election (JOI22_ho_t3)C++17
100 / 100
380 ms6540 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t typedef long double ld; const int maxn = 501; ld dp[maxn][maxn]; int pr[maxn][maxn]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(18); int n,k; cin >> n >> k; vector<pair<int,int>> ab(n); for(int i = 0;i < n;++i) { cin >> ab[i].second >> ab[i].first; if(ab[i].first == -1) { ab[i].first = 1e18; } } sort(ab.begin(),ab.end()); for(int pos = 0;pos < n;++pos) { vector<int> cc; for(int j = pos;j < n;++j) { cc.push_back(ab[j].second); } sort(cc.begin(),cc.end()); pr[pos][0] = 0; for(int j = 0;j < cc.size();++j) { pr[pos][j+1] = pr[pos][j] + cc[j]; } } ld ans = 1e18; for(int kb = 0;kb <= k;++kb) { for(int i = n;i >= 0;--i) { for(int j = 0;j <= kb;++j) { if(i == n) { dp[i][j] = (j == kb ? 0 : 1e18); } else if(j == kb) { dp[i][j] = (i > k ? 1e18 : ld(pr[i][k-i])/(kb+1)); } else { dp[i][j] = min(dp[i+1][j+1]+ld(ab[i].first)/(j+1),dp[i+1][j]+ld(ab[i].second)/(kb+1)); } } } ans = min(ans,dp[0][0]); } cout << ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:40:25: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int j = 0;j < cc.size();++j)
      |                       ~~^~~~~~~~~~~
#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...