#include <iostream> #include <vector> #include <string> #include <algorithm> #include <deque> #include <stack> #include <iterator> #include <numeric> #include <tuple> #include <set> #include <functional> typedef unsigned long long ULL; typedef unsigned long UL; typedef unsigned int UI; typedef long long LL; typedef std::pair<long, long> PLL; typedef std::tuple<LL, LL, LL> PLLL; int main(int argc, char **argv) { int n; std::cin>>n; std::set<UI, std::greater<UI>> coins; UI coin; for(int i = 0; i < n; ++i) { std::cin>>coin; auto ins = coins.insert(coin); while(!ins.second) { coins.erase(coin); coin++; ins = coins.insert(coin); } } auto res = coins.begin(); std::cout<<*res<<std::endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <iostream> #include <vector> #include <string> #include <algorithm> #include <deque> #include <stack> #include <iterator> #include <numeric> #include <tuple> #include <set> #include <functional> typedef unsigned long long ULL; typedef unsigned long UL; typedef unsigned int UI; typedef long long LL; typedef std::pair<long, long> PLL; typedef std::tuple<LL, LL, LL> PLLL; int main(int argc, char **argv) { int n; std::cin>>n; std::set<UI, std::greater<UI>> coins; UI coin; for(int i = 0; i < n; ++i) { std::cin>>coin; auto ins = coins.insert(coin); while(!ins.second) { coins.erase(coin); coin++; ins = coins.insert(coin); } } auto res = coins.begin(); std::cout<<*res<<std::endl; return 0; } |