1 solutions
-
0
C++ :
#include <iostream> #include "bit" #include "vector" #include "unordered_set" #include "set" #include "queue" #include "algorithm" #include "bitset" using namespace std; const int N = 2e5 + 2; int n, a[10], b[10], c[10], ans = 1e9; void f(int i) { if (i == n) { int s = 1; for(int j = 1; j < n; j++){ s += max(b[c[j - 1]], a[c[j]]) + 1; } ans = min(ans, s); return; } for (int k = i; k < n; k++) { swap(c[i], c[k]); f(i + 1); swap(c[i], c[k]); } } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i], c[i] = i; f(0); cout << ans; }
- 1
Information
- ID
- 117
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By