Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,m,i,j;
- while(scanf("%d%d",&n,&m) && (n||m))
- {
- vector<int>dragon(n);
- vector<int>knight(m);
- for(i=0; i<n; i++)
- {
- scanf("%d",&dragon[i]);
- }
- for(i=0; i<m; i++)
- {
- scanf("%d",&knight[i]);
- }
- sort(dragon.begin(),dragon.end());
- sort(knight.begin(),knight.end());
- int coin;
- i = j = coin = 0;
- while(i<n && j<m)
- {
- while(dragon[i]>knight[j] && j<m)
- {
- j++;
- }
- if(j==m)
- {
- break;
- }
- coin+=knight[j];
- i++;j++;
- }
- if(i==n)
- {
- printf("%d\n",coin);
- }
- else
- {
- printf("Loowater is doomed!\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment