HR_Array Manipulation
第一版有7个时间超限,优化成了第二版:
1:
#!/bin/python3 import math
import os
import random
import re
import sys # Complete the arrayManipulation function below.
def arrayManipulation(n, queries):
# n is lenth m is operatation
m = len(queries)
arr = [0]*n
for i in range(m):
start = queries[i][0]
end = queries[i][1]
for j in range (start -1, end):
arr[j] += queries[i][2]
return max(arr)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w') nm = input().split() n = int(nm[0]) m = int(nm[1]) queries = [] for _ in range(m):
queries.append(list(map(int, input().rstrip().split()))) result = arrayManipulation(n, queries) fptr.write(str(result) + '\n') fptr.close()
2:
#!/bin/python3 import math
import os
import random
import re
import sys # Complete the arrayManipulation function below.
def arrayManipulation(n, queries):
# n is lenth m is operatation
m = len(queries)
arr = [0]*(n+1)
for i in range(m):
start = queries[i][0]
end = queries[i][1]
arr[start - 1] += queries[i][2]
if (end <=len(arr)):
arr[end] -= queries[i][2] max =x =0
for i in arr:
x = x + i
if (max < x) : max =x
return max
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w') nm = input().split() n = int(nm[0]) m = int(nm[1]) queries = [] for _ in range(m):
queries.append(list(map(int, input().rstrip().split()))) result = arrayManipulation(n, queries) fptr.write(str(result) + '\n') fptr.close()
HR_Array Manipulation的更多相关文章
- backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.
昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec> <ctx>yMaint.ShrinkLog</ctx> ...
- Hololens开发笔记之Gesture手势识别(Manipulation手势控制物体旋转)
Manipulation gesture:保持点击手势,在3D世界中绝对运动 当你想要全息图像1:1响应用户手部移动时,操纵手势能被用于移动.缩放或旋转全息图像.如此的一个用处是使得用户可以在世界中绘 ...
- Hololens开发笔记之Gesture手势识别(Manipulation手势控制物体平移)
Manipulation gesture:保持点击手势,在3D世界中绝对运动 当你想要全息图像1:1响应用户手部移动时,操纵手势能被用于移动.缩放或旋转全息图像.如此的一个用处是使得用户可以在世界中绘 ...
- Track files and folders manipulation in Windows
The scenario is about Business Secret and our client do worry about data leakage. They want to know ...
- Data manipulation primitives in R and Python
Data manipulation primitives in R and Python Both R and Python are incredibly good tools to manipula ...
- VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟
C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/pr ...
- Bash String Manipulation Examples – Length, Substring, Find and Replace--reference
In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...
- windows phone 之手势识别(Manipulation)
在Windows Phone 7的多触摸屏上可以检测到至少四根同时存在的手指,并且一起操作使触摸屏充分发挥效果. 在silverlight开发中通过事件来实现触屏事件的检测,包括低级别的和高级别的接口 ...
- WPF Multi-Touch 开发:高级触屏操作(Manipulation)
原文 WPF Multi-Touch 开发:高级触屏操作(Manipulation) 在上一篇中我们对基础触控操作有了初步了解,本篇将继续介绍触碰控制的高级操作(Manipulation),在高级操作 ...
随机推荐
- O(N) 求数组中最大子串和
int MaxSubSum3(int *arr, int len) { int i; long long MaxSum = 0; long long CurSum = 0; for(int i = 0 ...
- bootstrap简单使用
Bootstrap (版本 v3.3.7) 官网教程: https://v3.bootcss.com/css/ row——行 row——列 push——推 pull——拉 col-md-o ...
- mysql 查看版本
查看mysql版本的四种方法 - 风生水起 - 博客园 http://www.cnblogs.com/end/archive/2011/10/18/2216461.html 查看mysql数据库版本方 ...
- css3 text-shadow字体阴影讲解
text-shadow:为字体添加阴影, 可以通过对text-shadow属性设置相关的属性值,来实现现一些需要的字体阴影效果,减少了图片的使用. 基础说明: text-shadow: X轴 ...
- sqlserver常用语法
--临时表 IF OBJECT_ID('tempdb..#Entry') is not null BEGIN DROP TABLE #Entry END ------------------- ...
- checkbox保存和赋值
//货物信息中的表格内容 $.each(trG.find('td input,td select'),function(i,inp){ if($(inp).attr('type')=='checkbo ...
- ubuntu 有些软件中不能输入中文
如果Ubuntu设定的是英文语言,在各种软件例如wps等中很有可能就不能输入中文.这种情况,我们的解决方案是,把中文输入法加到软件的启动文件中,如何加呢?把下面内容加进去就可以解决: export X ...
- java 中的迭代
package cn.zhou.com; import java.util.ArrayList; import java.util.Collection; import java.util.Itera ...
- Attention Model
参考1: https://blog.csdn.net/malefactor/article/details/50550211 attention部分实现: https://blog.csdn.net ...
- php1
正则表达式 $p = '/name:(\w+\s?\w+)/'; $str = "name:steven jobs"; preg_match($p, $str, $match); ...