Skip to content

Instantly share code, notes, and snippets.

@rishabhgargg
Created October 11, 2023 15:00
Show Gist options
  • Save rishabhgargg/d5551cc39ce7185dfd0207928120cd65 to your computer and use it in GitHub Desktop.
Save rishabhgargg/d5551cc39ce7185dfd0207928120cd65 to your computer and use it in GitHub Desktop.
Raghav 1
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector state(N);
vector distance(N);
for (int i = 0; i < N; i++) {
cin >> state[i];
}
for (int i = 0; i < N; i++) {
cin >> distance[i];
}
int cableLength = 0;
int lastOnIndex = -1;
for (int i = 0; i < N; i++) {
if (state[i] == 1) {
if (lastOnIndex != -1) {
cableLength += distance[i] - distance[lastOnIndex];
}
lastOnIndex = i;
}
}
cout << cableLength << endl;
return 0;
}
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment