Skip to content

Commit

Permalink
Create 1894_Find_the_Student_that_Will_Replace_the_Chalk.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing-avil authored Sep 2, 2024
1 parent 472fafd commit e50ed9e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 1894_Find_the_Student_that_Will_Replace_the_Chalk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ███████╗ █████╗ ███╗ ██╗ ██████╗ █████╗ ██████╗ ██████╗ ██╗ ██╗
// ██╔════╝ ██╔══██╗ ████╗ ██║ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██║ ██║
// ███████╗ ███████║ ██╔██╗ ██║ ██║ ██║ ███████║ ██████╔╝ ██████╔╝ ███████║
// ╚════██║ ██╔══██║ ██║╚██╗██║ ██║ ██║ ██╔══██║ ██╔═██╗ ██╔══██╗ ██╔══██║
// ███████║ ██║ ██║ ██║ ╚████║ ██████╔╝ ██║ ██║ ██║ ██╗ ██████╔╝ ██║ ██║
// ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
#pragma GCC optimize("Ofast", "inline", "ffast-math", "unroll-loops","no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native", "f16c")
auto init = []() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 'c';
}();
class Solution {
public:
int chalkReplacer(vector<int>& chalk, int k) {
long long sum= accumulate(chalk.begin(), chalk.end(), 0LL);
k = k%sum;
for(int i=0; i<chalk.size(); i++){
if(k<chalk[i]){
return i;
}
k-=chalk[i];
}
return -1;
}
};

0 comments on commit e50ed9e

Please sign in to comment.