diff --git a/Greedy/1343.cpp b/Greedy/1343.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8170637784abd69ba2f707c3af1c1d29f42a8167 --- /dev/null +++ b/Greedy/1343.cpp @@ -0,0 +1,67 @@ +#include<iostream> +#include<string> +using namespace std; + +int main() +{ + string A = "AAAA"; + string B = "BB"; + string input, output = ""; + + cin >> input; + + int s = 0; + int flag = 0; + for(int i=0;i<input.length();i++) + { + if(input[i] == 'X') + continue; + + int len = i - s; + if(len % 2 == 1) + { + flag = 1; + break; + } + + int four, two; + + four = len/4; + len -= four * 4; + + two = len/2; + + for(int i=0;i<four;i++) + output += A; + for(int i=0;i<two;i++) + output += B; + output += "."; + + s = i + 1; + } + + int len = input.length() - s; + if(len % 2 == 1) + { + flag = 1; + } + else + { + int four, two; + + four = len/4; + len -= four * 4; + + two = len/2; + + for(int i=0;i<four;i++) + output += A; + for(int i=0;i<two;i++) + output += B; + } + + if(flag == 1) + cout << -1 << endl; + else + cout << output << endl; +} \ No newline at end of file diff --git a/Greedy/14916.cpp b/Greedy/14916.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06a6593962d69e068b0099d073798066e0a49f52 --- /dev/null +++ b/Greedy/14916.cpp @@ -0,0 +1,27 @@ +#include<iostream> +using namespace std; + +int main() +{ + int N; + cin >> N; + + int five, two; + + five = N/5; + N -= five * 5; + + if(N % 2 == 0) + two = N/2; + else + { + five--; + N+=5; + two = N/2; + } + + if(five < 0) + cout << -1 << endl; + else + cout << five + two << endl; +} \ No newline at end of file diff --git a/Greedy/2217.cpp b/Greedy/2217.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c408275a6025097e44334fb6bb65f8e4496fd857 --- /dev/null +++ b/Greedy/2217.cpp @@ -0,0 +1,32 @@ +#include<iostream> +#include<vector> +#include<algorithm> +#include<functional> +using namespace std; + +int main() +{ + int N; + cin >> N; + + vector<int> v; + + for(int i=0;i<N;i++) + { + int a; + cin >> a; + v.push_back(a); + } + + sort(v.begin(), v.end(), greater<>()); + + int Max = 0; + for(int i=0;i<v.size();i++) + { + int now = (i + 1) * v[i]; + if(Max < now) + Max = now; + } + + cout << Max << endl; +} \ No newline at end of file diff --git a/README.md b/README.md index a64a9128c5856865a577260943040daa13dc412e..de2501cfbd96766059dd1b123ad626fc199f29aa 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,7 @@ ### 22.01.19 * Tree 끝 +### 22.02.15 + * Greedy 시작 +