Code in cpp only pass all test cases solve and wri...
Creato il: 13 luglio 2025
Creato il: 13 luglio 2025
pythonfrom PIL import Image import matplotlib.pyplot as plt img = Image.open('/mnt/data/20250713_175251.jpg') plt.imshow(img); plt.axis('off') (-0.5, 4623.5, 3467.5, -0.5)
pythonplt.figure(figsize=(6,10)) plt.imshow(img.rotate(90, expand=True)); plt.axis('off') (-0.5, 3467.5, 4623.5, -0.5)
pythonplt.figure(figsize=(6,10)) plt.imshow(img.rotate(-90, expand=True)); plt.axis('off') (-0.5, 3467.5, 4623.5, -0.5)
python# crop central area maybe plt.figure(figsize=(6,8)) plt.imshow(img.rotate(-90, expand=True).crop((0,0,1300,2500))); plt.axis('off') (-0.5, 1299.5, 2499.5, -0.5)
pythonimg2 = Image.open('/mnt/data/20250713_175302.jpg') plt.figure(figsize=(6,10)) plt.imshow(img2.rotate(-90, expand=True)); plt.axis('off') (-0.5, 3467.5, 4623.5, -0.5)
pythonimg3 = Image.open('/mnt/data/20250713_175316.jpg') plt.figure(figsize=(6,10)) plt.imshow(img3.rotate(-90, expand=True)); plt.axis('off') (-0.5, 3467.5, 4623.5, -0.5)
cpplong getMaximumScore(vector<int> arr, int k) { /* Any k indices can always be collected: pick the left-most of the remaining wanted indices each time and discard its left partition (which never contains a wanted element). Therefore the best total is simply the sum of the k largest values in the whole array. We only need the k largest values, not their order, so `nth_element` gives an O(n) solution and keeps memory small. */ if (k <= 0) return 0; const int n = arr.size(); k = min(k, n); // safety, though constraints guarantee k ≤ n nth_element(arr.begin(), // after this call arr.begin() + k, // the k-th position arr.end(), greater<int>()); // puts the k largest elements in front long long score = 0; // 64-bit to avoid overflow for (int i = 0; i < k; ++i) score += arr[i]; return static_cast<long>(score); // HackerRank’s `long` is 64-bit }