# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
580900 |
2022-06-22T05:44:04 Z |
web |
Sure Bet (CEOI17_sure) |
C++17 |
|
1 ms |
212 KB |
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
void output(double p1, double p2)
{
if(p1 < 0 ||p2<0)
printf("%.4lf", (double)(0));
else
printf("%.4lf", (double)(min(p1, p2)));
}
int main()
{
int n; cin>>n;
vector<double> odds1(n), odds2(n);
for(int i = 0; i<n; ++i)
{
cin>>odds1[i]>>odds2[i];
}
sort(odds1.rbegin(), odds1.rend());
sort(odds2.rbegin(), odds2.rend());
int currInvested = 0;
auto odd1It = odds1.rbegin()+1;
auto odd2It = odds2.rbegin()+1;
double profit1 = *(odds1.rbegin())-2;
double profit2 = *(odds2.rbegin())-2;
while(true)
{
if(odd1It == odds1.rend()|| odd2It == odds2.rend())
break;
//advance both until it is no longer locally optimal
if(profit1-2 + *(odd1It) >= profit1 && profit2 -2 + *(odd2It) >= profit2)
{
profit1 += -2 + *(odd1It);
profit2 += -2 + *(odd2It);
odd1It++; odd2It++;
}
else
{
break;
}
}
// cout<<"zwischnerg. : "<<profit1<<" "<<profit2<<endl;
//only advance one
if(profit1 > profit2)
{
if(odd2It == odds2.rend())
{
output(profit1, profit2);
return 0;
}
//advance second
while(profit1 -1 >= profit2 )
{
profit1--;
profit2 += *(odd2It)-1;
odd2It++;
if(odd2It == odds2.rend())
{
output(profit1, profit2);
return 0;
}
}
}
else
{
if(odd1It == odds1.rend())
{
output(profit1, profit2);
return 0;
}
//advance first
while(profit2 -1 >= profit1 )
{
profit2--;
profit1 += *(odd1It)-1;
odd1It++;
if(odd1It == odds1.rend())
{
output(profit1, profit2);
return 0;
}
}
}
output(profit1, profit2);
return 0;
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:29:9: warning: unused variable 'currInvested' [-Wunused-variable]
29 | int currInvested = 0;
| ^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |