Skip to content

Instantly share code, notes, and snippets.

@Klrfl
Last active August 24, 2026 03:12
Show Gist options
  • Select an option

  • Save Klrfl/d74f74792150953f226009fa52fc21db to your computer and use it in GitHub Desktop.

Select an option

Save Klrfl/d74f74792150953f226009fa52fc21db to your computer and use it in GitHub Desktop.
Pemanasan gemastik A
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <utility>
int main() {
int n;
std::cin >> n;
if(n == 1) {
std::cout << "SESUAI";
return 0;
}
std::map<int, int> uniq_map;
int new_glass;
for (int i = 0; i < n; i++) {
std::cin >> new_glass;
auto existing = uniq_map.find(new_glass);
if(existing == uniq_map.end()) {
uniq_map.insert(std::make_pair(new_glass, i+1));
}
if (uniq_map.size() > 3) {
std::cout << "TIDAK SESUAI\n";
return 0;
} else if (uniq_map.size() == 3 && (existing == uniq_map.begin() || existing == --uniq_map.end())) {
std::cout << "TIDAK SESUAI\n";
return 0;
}
}
if(uniq_map.size() == 1) {
std::cout << "SESUAI\n";
return 0;
}
auto min = uniq_map.cbegin(); // std::map is sorted
auto max = uniq_map.crbegin();
float avg = (min->first + max->first) / 2.0;
bool is_pourable = ceilf(avg) == avg; // is avg an int?
auto mid = std::prev(max);
if(bool mid_exists = mid != uniq_map.crend(); mid_exists) {
is_pourable = is_pourable && avg == mid->first;
}
if(!is_pourable) {
std::cout << "TIDAK SESUAI\n";
return 0;
}
int pour_amount = max->first - avg;
int from = max->second;
int to = min->second;
std::cout << pour_amount << " " << from << " " << to << "\n";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
// not actually the submitted file
// there was another else if block that was deleted at :35
int main() {
int n; cin >> n;
vector<int> gelas (n);
map<int,int> gelasmap;
for(int i=0; i<n; i++) {
cin >> gelas[i];
gelasmap.insert(make_pair(gelas[i], i+1));
}
sort(gelas.begin(), gelas.end());
int unik = 1;
int m;
for(int i=1; i<n; i++) {
if(gelas[i-1]!=gelas[i]) unik++;
if(unik == 2) {
m = gelas[i];
}
}
if(unik > 3) {
cout << "TIDAK SESUAI" << endl;
} else if(unik == 1) {
cout << "SESUAI" << endl;
} else {
int avg = (gelas[0] + gelas[n-1]) /2;
// TODO
if(avg == m) {
cout << gelas[n-1]-m << " " << gelasmap[gelas[n-1]] << " " << gelasmap[gelas[0]] << endl;
} else {
cout << "TIDAK SESUAI" << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment