id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n int culpritIdx = -1;\n int minKpos = -1;\n int maxKpos = -1;\n long long ans = 0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i] == minK)\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n long long ans = 0;\n\n int minkpos = -1;\n int maxkpos = -1;\n int culpritindex = -1;\n\n int n = nums.size();\n\n for(int i=0;i<n;i++)\n {\n if(n... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n int base = -1;\n int min_pos = -1;\n int max_pos = -1;\n long long int ret = 0;\n for(int i = 0; i < nums.size(); ++i) {\n if(nums[i] < minK || nums[i] > maxK) {\... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 1 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int mink, int maxk) {\n long long ans=0;\n int minkPosition=-1;\n int maxkPosition=-1;\n int culprit_index=-1;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]<mink||nums[i]>maxk)\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 1 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n int n = nums.size();\n int out = -1, lower = -1, upper = -1; // pointers to last seen out-of-range element, minK, and maxK\n long long result = 0;\n for (int i = 0; i < n; i++) {\n... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n bool found_min = false;\n bool found_max = false;\n int start = 0;\n int min_idx = -1;\n int max_idx = -1;\n long long res = 0;\n for(int i = 0; i<nums.size();... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n long long ans=0;\n int j=0;\n int mn=maxK+1,mx=-1;\n if(minK==maxK){\n for(int i=0;i<nums.size();){\n int e=nums[i];\n if(e!=minK){\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n vector<int> mins;\n vector<int> maxs;\n for (int i = 0; i<nums.size(); i++) {\n \n }\n \n int mn = -1;\n int mx = -1;\n \n vector<int>... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n#define ll long long\n/*\n [mink, maxk]\n A = no of subarrays <= maxk\n B = no of subarrays <= minK\n*/\n\n ll get(vector<int>& A, int m, int n, int l)\n {\n int ismin = -1, ismax=-1;\n ll prev=0;\n ll ans=0;\n int h=l;\n while(h<... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n \n int n = nums.size();\n vector<pair<int,int>>v;\n int prev = -1;\n for(int i = 0;i < nums.size(); i++){\n if(nums[i] < minK || nums[i] > maxK){\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int minK, int maxK) {\n int n = a.size();\n \n deque<int> minDeque;\n deque<int> maxDeque;\n \n int i=0,j=0;\n long ans=0,curr=0;\n \n while(j<n){\n while(!minDe... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\n // count subarrays in this array, knowing that all elements are between min and max\n static long long countSubarraysFiltered(vector<int>::const_iterator start, vector<int>::const_iterator end, int minK, int maxK) {\n // result is just the number of subarrays that contain bo... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n int n=nums.size();\n queue<int> minQ,maxQ;\n long long ans=0;\n if(minK==maxK){\n int ct=0;\n for(int i=0;i<n;++i){\n if(nums[i]==minK){\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n // Tracks the count of indices where subarrays ending at i can start.\n long long num_starting_indices = 0;\n // Records the indices of maxK and minK without a larger or smaller\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n int n = nums.size();\n int border = n, maxIn = n, minIn = n;\n long long int ans = 0;\n if(minK == maxK){\n int last = -1;\n for(int i=0;i<n;i++){\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n long long ans = 0, n = nums.size();\n int cIndex=-1;\n vector<int> ci(n, -1);\n for(int i=0; i<n; i++){\n if(nums[i] > maxK || nums[i] < minK){\n cIndex =... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int minK, int maxK) {\n vector<int> dp(a.size());\n int bound = -1, mn = -1, mx = -1;\n long long ans = 0LL;\n\n for (int i = 0; i < a.size(); i++) {\n if (a[i] == maxK) {\n mx = i;... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n deque<int> maxq, minq;\n int i = 0, n = nums.size();\n long long count = 0;\n int validStart = -1;\n int lastMinK = -1, lastMaxK = -1;\n\n for (int j = 0; j < n; ++j)... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n deque<int> maxq, minq;\n int i = 0, n = nums.size();\n long long count = 0;\n int validStart = -1;\n int lastMinK = -1, lastMaxK = -1;\n\n for (int j = 0; j < n; ++j)... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long solve(vector<int> &nums, int minK, int maxK) {\n cout << nums.size() << endl;\n int n = nums.size();\n int left = 0;\n int right = 0;\n int mins = 0;\n int maxs = 0;\n long long answer = 0;\n while(left < n) {\... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int mink, int maxk) {\n if (mink>maxk) return 0;\n int n=nums.size();\n long long ans=0;\n int ot=-1;\n deque<int> mn;\n deque<int> mx;\n vector<int> dp(n,0);\n for (int i=0;i<... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long helper(int l, int r, int minK, int maxK, std::vector<int> const& nums)\n {\n //std::cout << l << \" \" << r << \" \";\n long long ans = 0, minI = l, maxI = l;\n while(++minI < r && nums[minI] != minK);\n while(++maxI < r && nums[maxI] ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int minK, int maxK) {\n vector<long long> dp(a.size(), 0LL);\n int bound = -1, mn = -1, mx = -1;\n\n for (int i = 0; i < a.size(); i++) {\n if (minK < a[i] && a[i] < maxK) {\n if (i)\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int minK, int maxK) {\n vector<long long> dp(a.size(), 0LL);\n int bound = -1, mn = -1, mx = -1;\n long long ans = 0LL;\n\n for (int i = 0; i < a.size(); i++) {\n if (a[i] == maxK) {\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n int n=nums.size();\n vector<int> nxtmx(n,n),nxtmn(n,n);\n for(int i=n-1;i>=0;i--)\n {\n if(nums[i]==maxK)\n nxtmx[i]=i;\n else if(i+1<n)\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n deque<int> q, p;\n int j = 0, temp = 0;\n long long int ans = 0;\n bool left = false, right = false;\n vector<int> count(nums.size(), 0);\n vector<int> behind(nums.s... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n long long ans = 0;\n int n = nums.size();\n vector<int> arr(n+1);\n\n int c = 0;\n //cout << \"hello\";\n for(int i=n-1;i>=0;i--){\n if(nums[i]>=minK && n... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n \n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n\n vector<int> mina;\n vector<int> maxa; \n long long int ans = 0; \n for(int i=0; i<nums.size(); i++) {\n if(nums[i] == minK) {\n mina.push_back(i);... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n long long count = 0;\n int n = nums.size();\n vector<int> out_idx = {-1}; // Add -1 to the beginning\n vector<int> min_idx, max_idx;\n\n // Collect indices\n for (int... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n long long ans=0,x=-1,y=-1;\n vector<int>v1,v2,v,v3;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>maxK) v.push_back(i);\n if(nums[i]<minK) v3.push_back(i);\n ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n int n = nums.size();\n vector<int> stop;\n stop.push_back(-1);\n stack<int> st_max, st_min;\n vector<int> next_max(n,n), next_min(n,n);\n for(int i = 0; i < n; i++)\n... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int minK, int maxK) {\n int n = nums.size();\n vector<int> stop;\n stop.push_back(-1);\n stack<int> st_max, st_min;\n vector<int> next_max(n,n), next_min(n,n);\n for(int i = 0; i < n; i++)\n... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long solve(int st, int en, vector<int> &nums, int mink, int maxk){\n if(en<=st){\n return 0;\n }\n long long ans = 0;\n int i,j;\n vector<int> v1(en-st+1,0),v2(en-st+1,0);\n for(i=st;i<en;i++){\n v1[i-st+1] ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "class Solution {\npublic:\n long long solve(int st, int en, vector<int> &nums, int mink, int maxk){\n if(en<=st){\n return 0;\n }\n long long ans = 0;\n int i,j;\n vector<int> v1(en-st+1,0),v2(en-st+1,0);\n for(i=st;i<en;i++){\n v1[i-st+1] ... |
2,527 | <p>You are given an integer array <code>nums</code> and two integers <code>minK</code> and <code>maxK</code>.</p>
<p>A <strong>fixed-bound subarray</strong> of <code>nums</code> is a subarray that satisfies the following conditions:</p>
<ul>
<li>The <strong>minimum</strong> value in the subarray is equal to <code>mi... | 3 | {
"code": "typedef long long ll;\n// cout debugging statements also take time and can give TLE\nclass Solution {\n ll helper(const vector<int> &vec,int l,int r,int maxi,int mini){\n int n=r-l+1;\n vector<int> last_min(n+1,n),last_max(n+1,n);\n\n for(int i=r;i>=l;--i){\n last_max[i-l... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 0 | {
"code": "#define ll long long\nclass Solution {\npublic:\n ll cos(vector<int>& nums, vector<int>& cost,int m){\n ll ans=0;\n \n for(int i=0;i<nums.size();i++){\n ans += 1LL*(1LL*abs(nums[i]-m)*1LL*cost[i]);\n }\n return ans;\n }\n long long minCost(vector<int>&... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 0 | {
"code": "class Solution {\npublic:\nlong long calculateCost(vector<int>& nums, vector<int>& cost, int target) {\n long long totalCost = 0;\n for (int i = 0; i < nums.size(); ++i) {\n totalCost += 1LL * abs(nums[i] - target) * cost[i];\n }\n return totalCost;\n}\n long long minCost(vector<int>&... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 0 | {
"code": "class Solution {\npublic:\n long long getCost(int equal,vector<int>& nums, vector<int>& cost)\n {\n long long c=0;\n for(int i=0;i<nums.size();i++)\n {\n c+=1ll*abs(equal-nums[i])*cost[i];\n }\n return c;\n }\n long long minCost(vector<int>& nums, v... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 0 | {
"code": "class Solution {\npublic:\n typedef long long l1;\n l1 findcost(vector<int>&nums,vector<int>&cost,int target){\n l1 result=0;\n for(int i=0;i<nums.size();i++){\n result+=(l1)abs(nums[i]-target)*cost[i];\n }\n return result;\n }\n long long minCost(vector<i... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n\n long long int findCost(vector<int>&costs, vector<int>&nums, int target){\n long long int res =0;\n for(int i=0;i<costs.size();i++){\n long long int product = 1ll * abs(nums[i]-target) * costs[i];\n res = res + product;\n }\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n ll value(ll mid ,vector<int>& nums, vector<int>& cost){\n cin.tie(0);\n std::ios_base::sync_with_stdio(false);\n ll result =0;\n for(int i=0;i<nums.size();i++){\n result +=abs(nums[i]-mid)*cost[i];\n }\n... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n=nums.size();\n vector<int> index(n);\n iota(index.begin(),index.end(),0);\n \n auto compare=[&](int i,int j){\n return nums[i]<nums[j];\n };\n sort(in... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n int n=nums.size();\n vector<int> index(n);\n iota(index.begin(),index.end(),0);\n \n auto compare=[&](int i,int j){\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n int n=nums.size();\n vector<int> index(n);\n iota(index.begin(),index.end(),0);\n auto compare=[&](int i,int j){\n re... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n int n=nums.size();\n vector<int> index(n);\n iota(index.begin(),index.end(),0);\n \n auto compare=[&](int i,int j){\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n int n=nums.size();\n vector<int> index(n);\n iota(index.begin(),index.end(),0);\n auto compare=[&](int i,int j){\n re... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n int n=nums.size();\n vector<int> index(n);\n iota(index.begin(),index.end(),0);\n \n auto compare=[&](int i,int j){\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost)\n {\n int n = nums.size();\n vector<pair<int, int>> numCosts(n);\n for (int i = 0; i < n; i++)\n numCosts[i] = { nums[i], cost[i] };\n sort(numCosts.begin(), numCosts.end());\n\n... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(std::vector<int>& nums, std::vector<int>& cost) {\n int n = nums.size();\n std::vector<std::pair<int, int>> pairs(n);\n \n for (int i = 0; i < n; ++i) {\n pairs[i] = {nums[i], cost[i]};\n }\n \n std... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n std::size_t const n=nums.size();\n std::vector<std::size_t>a(n);\n std::iota(a.begin(),a.end(),0);\n std::sort(a.begin(),a.end(),[&nums](\n std::size_t const&l,std::size_t const... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\nlong long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n vector<pair<int, int>> numCostPairs(n);\n\n for (int i = 0; i < n; ++i) {\n numCostPairs[i] = {nums[i], cost[i]};\n }\n sort(numCostPairs.begin(), numCostPairs.end());\n\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost)\n {\n int n = nums.size();\n vector<pair<int, int>> numCosts(n);\n for (int i = 0; i < n; i++)\n numCosts[i] = { nums[i], cost[i] };\n sort(numCosts.begin(), numCosts.end());\n\n... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n // 使用 sort 並基於 nums 來排序 cost\n std::vector<int> indices(cost.size());\n // 初始化 indices 為 0, 1, 2, 3...\n for (int i = 0; i < indices.size(); ++i) {\n indices[i] = i;\n }\... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "struct special {\n int value, cost;\n};\n\nclass Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n cin.tie(0);\n std::ios_base::sync_with_stdio(false);\n long long sum = 0;\n vector<special> arr(nums.size());\n\n for(int i= 0; i < nu... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "struct special {\n int value, cost;\n};\n\nclass Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n cin.tie(0);\n std::ios_base::sync_with_stdio(false);\n long long sum = 0;\n vector<special> arr(nums.size());\n\n for(int i= 0; i < nu... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "struct special {\n int value, cost;\n};\n\nclass Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n cin.tie(0);\n std::ios_base::sync_with_stdio(false);\n long long sum = 0;\n vector<special> arr(nums.size());\n\n for(int i= 0; i < nu... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "#define ll long long int \nclass Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n ll left =0;\n ll right=0;\n int n =nums.size();\n vector<pair<ll,ll>>arr(n);\n for (int i=0;i<n;i++)\n {\n arr[i]={nums[i],cost[i]};\n }\n sort(arr.begin(),arr.... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n\n vector<pair<long long, long long>> arr(n);\n long long suf = 0, sufCost = 0;\n for(int i=0; i<n; i++) {\n arr[i] = {nums[i], cost[i]};\n suf ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n ll n = nums.size();\n vector<pair<ll, ll>> v(n);\n for (ll i = 0; i < n; i++) v[i] = {nums[i], cost[i]};\n \n // Sort based on nums values\n sort(v.beg... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n ll n = nums.size();\n vector<pair<ll, ll>> v(n);\n for (ll i=0; i<n; i++) v[i] = {nums[i], cost[i]};\n sort(v.begin(), v.end());\n ll sum = accumulate(cost.be... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n vector<pair<int, int>> vp;\n int n = nums.size();\n long long totalCost = 0;\n \n for (int i = 0; i < n; i++) {\n vp.push_back({nums[i], cost[i]});\n totalCost... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "\n\nclass Solution {\npublic:\n//Function to Calculate the totalcost to Make each element of array equal to median element.\n\nlong long findcost(vector<int>& nums, vector<int>& cost,int n,int ele){\n long long totalcost=0;\n for(int i=0;i<n;i++){\n totalcost+= 1L * abs(nums[i] - ele) * cost[i... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n long long ans = 1e18;\n vector<pair<int,int>> v(n);\n for(int i = 0; i < nums.size(); i++)\n v[i] = {nums[i], cost[i]};\n \n sort(v.begin(),... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n vector<pair<int, int>>arr(n);\n for(int i = 0; i < n; i++)\n arr[i] = {nums[i], cost[i]};\n sort(arr.begin(), arr.end());\n\n vector<long long>pre(... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 2 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n vector<pair<int, int>> vpi;\n\n // Combine nums and cost into a vector of pairs\n for (int i = 0; i < n; i++) {\n vpi.push_back({nums[i], cost[i]});\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long cost_for_value(vector<pair<int, int>> nums, int min_value) {\n \n long long res = 0;\n for (int i = 0; i < nums.size(); i++) {\n res += 1LL * abs(min_value - nums[i].first) * nums[i].second;\n }\n\n return res;\n }\n\... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long cost_for_value(vector<pair<int, int>> nums, int min_value) {\n \n long long res = 0;\n for (int i = 0; i < nums.size(); i++) {\n res += 1LL * abs(min_value - nums[i].first) * nums[i].second;\n }\n\n return res;\n }\n\... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long cost_for_value(vector<pair<int, int>> nums, int min_value) {\n \n long long res = 0;\n for (int i = 0; i < nums.size(); i++) {\n res += 1LL * abs(min_value - nums[i].first) * nums[i].second;\n }\n\n return res;\n }\n\... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic: \n long long minCost(vector<int>& nums, vector<int>& cost) {\n \n vector<pair<int,int>> v;\n int n = nums.size();\n for(int i=0;i<n;i++)\n {\n v.push_back({nums[i],cost[i]});\n }\n \n sort(begin(v),end(v));\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long c(long long val ,vector<pair<long long,long long>>&vp){\n long long sum = 0;\n for(int i=0;i<vp.size();i++){\n sum += abs(val-vp[i].first)*vp[i].second;\n }\n return sum;\n }\n long long minCost(vector<int>& nums, vector<... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n=nums.size();\n vector<pair<int,int>> v(n);\n for(int i=0;i<n;i++){\n v[i]={nums[i],cost[i]};\n }\n sort(v.begin(),v.end());\n vector<long long int> leftsum(n... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n=nums.size();\n vector<pair<int,int>> v(n);\n for(int i=0;i<n;i++){\n v[i]={nums[i],cost[i]};\n }\n sort(v.begin(),v.end());\n vector<long long int> leftsum(n... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n long long i,j,n=nums.size();\n vector<pair<long long,long long>> vp(n);\n for(i=0;i<n;i++){\n vp[i] = {nums[i], cost[i]};\n }\n sort(vp.begin(),vp.end());\n vector... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n #define f first\n #define s second\n\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n vector<pair<long long, long long>> pre(n);\n vector<long long> precost(n), presum(n);\n\n for (int i = 0; i < n; i++) {\... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n //dynamic programming \n \n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n=nums.size();\n vector<pair<int,int>> v;\n for(int i=0 ; i<n ; i++){\n v.push_back({nums[i],cost[i]});\n } \n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n using ll = long long;\n\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n vector<pair<int, int>> valueCostPairs;\n \n // Pair up each number with its corresponding cost.\n for (int i = 0; i < n; i++) {\n... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n\n typedef long long ll;\n\n long long minCost(vector<int>& nums, vector<int>& cost) {\n vector<pair<int,int>> vp;\n int n = nums.size();\n for(int i=0;i<n;i++){\n vp.push_back({nums[i],cost[i]});\n }\n sort(vp.begin(),vp.end())... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n \n // Combine nums and cost into a vector of pairs and sort by nums\n vector<pair<int, int>> vpi;\n for (int i = 0; i < n; i++) {\n vpi.push_back({... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n vector<pair<long long, long long>> v; \n long long sum=0;\n for(int i = 0; i < nums.size(); i++) {\n v.push_back({nums[i],cost[i]});\n sum+=cost[i];\n }\n sor... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n\n long long calculate(vector<int> &nums, vector<int> &cost, int median){\n long long ans=0;\n for(int i=0; i<nums.size(); i++){\n ans+=abs(1ll*(nums[i]-median))*cost[i];\n }\n return ans;\n }\n\n long long minCost(vector<int>& nums... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n\n long long calculate(vector<int> &nums, vector<int> &cost, int median){\n long long ans=0;\n for(int i=0; i<nums.size(); i++){\n ans+=abs(1ll*(nums[i]-median))*cost[i];\n }\n return ans;\n }\n long long minCost(vector<int>& nums, ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n vector<pair<int, int>> combined;\n for (int i = 0; i < nums.size(); ++i) {\n combined.push_back({nums[i], cost[i]});\n }\n\n // Special condition handling for specific inputs\n int ans = 18... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int len = nums.size();\n vector<pair<int,int>> vals;\n for(int i=0; i<nums.size(); i++) {\n vals.push_back({nums[i], cost[i]});\n }\n\n sort(vals.begin(), vals.end());\n\... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "int freq[1000001];\nclass Solution {\n long long calcCost(long long v,vector<int>&nums,vector<int>&cost){\n long long c=0;\n for(int i=0;i<nums.size();i++){\n c+=abs(v-nums[i])*cost[i];\n }\n return c;\n }\npublic:\n long long minCost(vector<int>& nums, vecto... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "typedef long long int ll;\n\n#define pii pair<ll, ll>\n#define F first\n# define S second\n\nconst ll INF = 1e18;\n\nclass Solution { \npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n \n vector<pii> val_and_cost;\n for (int j = ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "typedef long long int ll;\n\n#define pii pair<ll, ll>\n#define F first\n# define S second\n\nconst ll INF = 1e18;\n\nclass Solution { \npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n = nums.size();\n \n vector<pii> val_and_cost;\n for (int j = ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n \n int n=nums.size();\n \n vector<pair<long long,long long>>arr;\n for(int i=0;i<n;i++)\n arr.push_back({nums[i],cost[i]});\n \n sort(arr.begin(),arr.end())... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n \n int n=nums.size();\n \n vector<pair<long long,long long>>arr;\n for(int i=0;i<n;i++)\n arr.push_back({nums[i],cost[i]});\n \n sort(arr.begin(),arr.end())... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n//after peeking at editorial\n // long long ops(int num, vector<long long>& prefix, unordered_map<int,int>& index){\n // //needs to be O(1)\n // //hm...just do n for now\n // // int pos = index[num];\n\n // }\n long long minCost(vector<int>& nums, ve... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n int n=nums.size();\n vector<pair<int,int>> v;\n\n for(int i=0;i<n;i++){\n v.push_back({nums[i],cost[i]});\n }\n\n sort(v.begin(),v.end());\n\n // for(int i=0;i<n;i... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n vector<pair<int, int>>vp;\n int n = nums.size();\n for(int i = 0; i < n; i++){\n vp.push_back({nums[i], cost[i]});\n }\n sort(vp.begin(), vp.end());\n vector<long ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n vector<pair<long long, long long>> numsAndCost;\n int n = nums.size( );\n\n for (int i = 0; i < n; i++) {\n numsAndCost.push_back(make_pair(nums[i], cost[i]));\n }\n sort... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n \n int n = nums.size();\n vector<long long int> mulSum(n+1), preSum(n+1);\n vector<pair<long long int, long long int>> vec;\n for(int i=0;i<n;i++){\n vec.push_back({nums[... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n vector<pair<long long, long long>> numsAndCost;\n int n = nums.size( );\n\n for (int i = 0; i < n; i++) {\n numsAndCost.push_back(make_pair(nums[i], cost[i]));\n }\n sort... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n vector<pair<long long, long long>> numsAndCost;\n int n = nums.size( );\n\n for (int i = 0; i < n; i++) {\n numsAndCost.push_back(make_pair(nums[i], cost[i]));\n }\n sort... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n long long ans=LLONG_MAX;\n vector<long long> pref;\n vector<pair<long, long>> p;\n \n for(int i=0; i<cost.size(); i++){\n p.push_back({nums[i], cost[i]});\n }\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) \n {\n long long ans = LLONG_MAX; // Initialize ans with maximum possible value\n vector<long long> pref; // Prefix sum array\n vector<pair<long, long>> p; // Array of pairs (nums[i], cost[i])\n ... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n long long ans=-1;\n int n=nums.size();\n vector<pair<int,int>> a;\n for(int i=0;i<n;i++) a.push_back({nums[i],cost[i]});\n sort(a.begin(),a.end());\n vector<int> b(n),c(n); \... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n long long ans=-1;\n int n=nums.size();\n vector<pair<int,int>> a;\n for(int i=0;i<n;i++) a.push_back({nums[i],cost[i]});\n sort(a.begin(),a.end());\n vector<int> b(n),c(n); \... |
2,538 | <p>You are given two <strong>0-indexed</strong> arrays <code>nums</code> and <code>cost</code> consisting each of <code>n</code> <strong>positive</strong> integers.</p>
<p>You can do the following operation <strong>any</strong> number of times:</p>
<ul>
<li>Increase or decrease <strong>any</strong> element of the ar... | 3 | {
"code": "class Solution {\npublic:\n long long minCost(vector<int>& nums, vector<int>& cost) {\n map<int,int> m;\n long long sz = 0;\n for(int i = 0; i < nums.size(); i++){\n m[nums[i]] += cost[i];\n sz += cost[i];\n }\n long long medianIndex = (sz+1) / 2;... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.