#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int main()
{
int a,b, prvoPoluvrijeme = 0;
int koseviA[3000], koseviB[3000];
cin>>a;
for(int i=0;i<a;i++){
cin>>koseviA[i]; /// unosimo sekunde u kojima je tim A postigao kos
if(koseviA[i]<=1440) prvoPoluvrijeme++;
}
cin>>b;
for(int i=0;i<b;i++){
cin>>koseviB[i]; /// isto za tim B
if(koseviB[i]<=1440) prvoPoluvrijeme++;
}
/// 1, 5, 100, 250 - kosevi koje je tim a postigao
/// 3, 70, 125, 800 - kosevi koje je tim b postigao
/// 1,A 5,A 100 250 3 70 125 800
/// {1, A}, {3, B}, {5,A} , 70, 100, 125, 250, 800 - kombinovano
vector<pair<int, char>> sviKosevi;
for(int i=0;i<a;i++) sviKosevi.push_back( {koseviA[i], 'a'} );
for(int i=0;i<b;i++) sviKosevi.push_back( {koseviB[i], 'b'} );
sort(sviKosevi.begin(), sviKosevi.end());
int dosadA = 0, dosadB = 0, brojPreokreta=0;
char vodstvo = '?';
for(int i=0;i<sviKosevi.size();i++){
if( dosadA > dosadB ) vodstvo='a';
else if(dosadA < dosadB) vodstvo='b';
if( sviKosevi[i].second == 'a' )
dosadA++;
else dosadB++;
if( dosadA - dosadB == 1 && vodstvo == 'b' ){
brojPreokreta++;
vodstvo = 'a';
}
if( dosadB - dosadA == 1 && vodstvo == 'a' ){
brojPreokreta++;
vodstvo = 'b';
}
}
cout<<prvoPoluvrijeme <<endl;
cout<<brojPreokreta<<endl;
return 0;
}
Compilation message
preokret.cpp: In function 'int main()':
preokret.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0;i<sviKosevi.size();i++){
| ~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |