Task: | Cent saving |
Sender: | hefapa_aachen |
Submission time: | 2024-09-28 16:26:05 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.02 s | details |
Code
// ~/.vim/cpp_template.cpp #include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <string> #define REP(i,a,b) for (int i = a; i < b; i++) // Type Aliases for 1D and 2D vectors with initialization #define vi(n, val) vector<int>(n, val) // 1D vector of ints with size n, initialized to val #define vll(n, val) vector<long long>(n, val) // 1D vector of long longs with size n, initialized to val #define ll long long #define vvi(n, m, val) vector<vector<int>>(n, vector<int>(m, val)) // 2D vector of ints (n x m), initialized to val #define vvll(n, m, val) vector<vector<long long>>(n, vector<long long>(m, val)) // 2D vector of long longs (n x m), initialized to val using namespace std; template <typename T> void pV(const std::vector<T>& vec, const std::string& label = "Vector") { std::cout << label << ": [ "; for (const auto& elem : vec) { std::cout << elem << " "; } std::cout << "]" << std::endl; } using namespace std; void dfs(int s, vector<bool> *visited, vector<int> (*adj)[]) { if ((*visited)[s]) return; (*visited)[s] = true; // process node s for (auto u: (*adj)[s]) { dfs(u, visited, adj); } } /* vector<int> adj[N]; vector<bool> visited(N, false); int u, v; for(int i = 0; i < M;i++){ cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); } */ int main() { ios::sync_with_stdio(0); cin.tie(0); // Your code starts here int t; cin >> t; while (t--) { int n; cin >> n; int cnt3 = 0, cnt4 = 0; ll totalSum = 0; REP(i, 0, n) { ll p; cin >> p; totalSum += p - (p % 5); if (p % 5 == 3) cnt3++; if (p % 5 == 4) cnt4++; } int minCost = INT_MAX; for (int i = 0; 2 * i <= cnt3; ++i) { int currentCost = 5 * i; int usableCnt3 = cnt3 - 2 * i; int usableCnt4 = min(usableCnt3, cnt4); currentCost += 5 * usableCnt4; int remainingCnt4 = cnt4 - usableCnt4; currentCost += (remainingCnt4 / 3) * 10; currentCost += (remainingCnt4 % 3) * 5; currentCost += (usableCnt3 - usableCnt4) * 5; minCost = min(minCost, currentCost); } cout << totalSum + minCost << "\n"; } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
100 1000 528433894 255789530 559301042 ... |
correct output |
---|
475191144965 460688647850 478543444030 475238936090 456736521510 ... |
user output |
---|
475191144965 460688647850 478543444030 475238936090 456736521510 ... Truncated |
Test 2
Verdict: ACCEPTED
input |
---|
1 100000 666086355 190481330 514353517 ... |
correct output |
---|
47176864928795 |
user output |
---|
47176864928795 |