#include "jelly.h"
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
int n = a.size();
vector<pair<int, int>> a1, b1;
for(int i =0; i<n; i++){
pair<int, int> cost;
cost.first = a[i];
cost.second = i;
a1.push_back(cost);
cost.first = b[i];
b1.push_back(cost);
}
sort(a1.begin(), a1.end());
sort(b1.begin(), b1.end());
int X = x, Y = y;
int variety = 0;
vector <int> bought;
for(int j=0; j<n; j++){
int presA = 0, presB = 0;
if(a1[j].second == b1[j].second){//same flavor
if(a1[j].first<=b1[j].first){ //lowest price
if(X<=a1[j].first){
X-=a1[j].first;
variety++;
bought.push_back(a1[j].second);
}
else if(Y<=b1[j].first){//if x doesn't have enough
Y-=b1[j].first;
variety++;
bought.push_back(b1[j].second);
}
} else{
if(Y<=b1[j].first){//if x doesn't have enough
Y-=b1[j].first;
variety++;
bought.push_back(b1[j].second);
}
else if(X<=a1[j].first){
X-=a1[j].first;
variety++;
bought.push_back(a1[j].second);
}
}
}
else{
int sizBo = bought.size();
for(int k = 0; k<sizBo; k++){
if(bought[k] == a1[j].second){
presA++;
break;
}
else if(bought[k] == b1[j].second){
presB++;
break;
}
}
if(a1[j].first<=b1[j].first){ //lowest price
if(X<=a1[j].first && presA!= 1){
X-=a1[j].first;
variety++;
bought.push_back(a1[j].second);
}
else if(Y<=b1[j].first && presB!= 1){
Y-=b1[j].first;
variety++;
bought.push_back(b1[j].second);
}
}
}
}
return variety;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
1st lines differ - on the 1st token, expected: '8', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
1st lines differ - on the 1st token, expected: '8', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
1st lines differ - on the 1st token, expected: '689', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
1st lines differ - on the 1st token, expected: '62', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
1st lines differ - on the 1st token, expected: '154', found: '877' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
1st lines differ - on the 1st token, expected: '8', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |